Skip to content

Instantly share code, notes, and snippets.

@rafaelcardoso
Created April 6, 2013 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelcardoso/5327707 to your computer and use it in GitHub Desktop.
Save rafaelcardoso/5327707 to your computer and use it in GitHub Desktop.
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