Sorting of ArrayList shows first item twice

45
January 12, 2019, at 6:50 PM

i try to Sort my arrayList depending on the distance between user and the location. To do this i created the following two methods:

   private void getDistanceBetweenUserAndMarket(ArrayList<SellerObject> seller) {
    for (int  i = 0; i<seller.size(); i++) {
        SellerObject se = seller.get(i);
        Location storeLoc = new Location("");
        storeLoc.setLatitude(Double.parseDouble(se.getLat()));
        storeLoc.setLongitude(Double.parseDouble(se.getLng()));
        if (storeLoc != null && mlastLocation != null) {
            Float distanceInMetres = mlastLocation.distanceTo(storeLoc);
            Float distanceInKm = distanceInMetres / 1000;
            DecimalFormat df = new DecimalFormat("#.##");
            se.setDistance(distanceInKm);
            seller.set(i, se);
        }
    }
    sortArrayList(seller);
}
private void sortArrayList(ArrayList<SellerObject> seller) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        seller.sort(Comparator.comparing(SellerObject::getDistance));
    }
    getProducts(seller);
}

the duplicates were created by the last method. Also a strange phenomen is that sometimes the highest value is at the top sometimes the lowest. I would like to have the lowest value at the top

READ ALSO
How to customize SwipeToReferesh layout top ProgressBar or Loader?

How to customize SwipeToReferesh layout top ProgressBar or Loader?

I would like to know how can I customize SwipeToRefresh layoutIn specific, I am trying to hide that loader

29
How to solve dlopen failed: library &ldquo;../../lib/libtbb.so&rdquo; not found error?

How to solve dlopen failed: library “../../lib/libtbb.so” not found error?

I am working on android app with Face Recognization using OpenCvI found this repo here's a link

28
Dagger 2 get old token when token is refreshed

Dagger 2 get old token when token is refreshed

I am having a problem with dagger 2Briefly, dagger 2 makes the injection in my fragment, and if the token is expired

24
How to get login() &gt; 0 for this rest api code [on hold]

How to get login() > 0 for this rest api code [on hold]

I need the result of this coding is login () > 0, where is the wrong code ?

50