public int compare(Branch b1, Branch b2) { double d1 = b1.getDistFromUser(); double d2 = b2.getDistFromUser(); if (d1 < d2) return -1; if (d1 > d2) return 1; return 0; }
private void setupNearestBranchesAdapter() { Log.d(APP_TAG, "Branches after sort = " + branches); // initialize our list to pass to the adapter. The adapter // needs the names and the distances of the branches to show // the information ArrayList<Pair<String, Double>> branchesWithDistance = new ArrayList<Pair<String, Double>>(); for (Branch branch : nearestBranchesList) { String name = branch.getName(); Double distance = branch.getDistFromUser(); Pair<String, Double> pair = new Pair<String, Double>(name, distance); branchesWithDistance.add(pair); } nearestBranchesAdapter = new BranchLocationAdapter(getActivity(), branchesWithDistance); this.setListAdapter(nearestBranchesAdapter); }