androidfacebooklistview

Listview in alphabetical order


I have a listview that gets facebook friends, and i would like to sort the names in alphabetical order, but im not very sure how to go on and do this.

Here is the code:

@Override
        public void onComplete(List<Profile> friends) {
            // populate list
            List<String> values = new ArrayList<String>();
            for (Profile profile : friends) {
                //profile.getInstalled();
                values.add(profile.getName());
            }
            ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
            mFriendsList.setAdapter(friendsListAdapter);

        }
    };

I have looked around for solutions but didn't find for arraydapter.


Solution

  • you can use ArrayAdapter.sort

    friendsListAdapter.sort(new Comparator<String>() {
        @Override
        public int compare(String lhs, String rhs) {
            return lhs.compareTo(rhs);    
        }
    });