Created
April 6, 2013 21:31
-
-
Save rafaelcardoso/5327707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StableArrayAdapter extends ArrayAdapter<Contact> { | |
HashMap<Contact, Integer> mIdMap = new HashMap<Contact, Integer>(); | |
public StableArrayAdapter(Context context, int textViewResourceId, List<Contact> objects) { | |
super(context, textViewResourceId, objects); | |
for (int i = 0; i < objects.size(); ++i) { | |
mIdMap.put(objects.get(i), i); | |
} | |
} | |
@Override | |
public long getItemId(int position) { | |
Contact item = getItem(position); | |
return mIdMap.get(item); | |
} | |
@Override | |
public boolean hasStableIds() { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment