Pradeep Sodhi
Pradeep Sodhi

Reputation: 2145

Populate listview according to distance

I am using gooleplaces API. I have a response in json, but the problem is I want to populate listview according to distance. I make the sorted distance arraylist in ascending order using collections.sort(), but how do I sort other lists based on this sorted list to populate my listview correctly?

Upvotes: 0

Views: 453

Answers (2)

Pradeep Sodhi
Pradeep Sodhi

Reputation: 2145

Finally I resolve my problem using bubble sort.

if (distanceList.size()>1) // check if the number of orders is larger than 1
            {
                for (int i=0; i<distanceList.size()-1; i++) // bubble sort outer loop
                {
                    for (int j=0; j < distanceList.size()-1-i; j++) {

                        if (distanceList.get(j)>(distanceList.get(j+1)) )
                        {
                         int temp = distanceList.get(j);
                           distanceList.set(j,distanceList.get(j+1) );
                           distanceList.set(j+1, temp);

                           String temp1 = nameList.get(j);
                           nameList.set(j,nameList.get(j+1) );
                           nameList.set(j+1, temp1);

                           String temp2 = vicinityList.get(j);
                           vicinityList.set(j,vicinityList.get(j+1) );
                           vicinityList.set(j+1, temp2); 

                           String temp3 = latList.get(j);
                           latList.set(j,latList.get(j+1) );
                           latList.set(j+1, temp3);

                           String temp4 = longList.get(j);
                           longList.set(j,longList.get(j+1) );
                           longList.set(j+1, temp4);


                        }
                    }
                }
            }

Upvotes: 0

jeet
jeet

Reputation: 29199

If you are creating separate lists, then you need to your define method, and if you are using list of single collection, or data structure, you can define your comparator, then call sort on this, list.

Upvotes: 1

Related Questions