Skip to content

Instantly share code, notes, and snippets.

@pboos
Created June 19, 2012 01:21
Show Gist options
  • Save pboos/2951782 to your computer and use it in GitHub Desktop.
Save pboos/2951782 to your computer and use it in GitHub Desktop.
selectable adapter
private Set<String> mSelectedContactNumbers = new HashSet<String>();
@Override
public void bindView(View view, Context context, final Cursor cursor)
{
final String contactNumber = cursor.getString(cursor.getColumnIndex("contact_number"));
view.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (!mSelectedContactNumbers.remove(contactNumber)) {
mSelectedContactNumbers.add(contactNumber);
}
notifyDataSetChanged();
}
});
if (mSelectedContactNumbers.contains(contactNumber)) {
view.setBackgroundColor(0xff333333);
} else {
view.setBackgroundColor(0);
}
createView(view, cursor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment