I currently have a ListView that activates an ActionBar context in a ListView OnItemLongClickListener .
I am trying to make the elements selectable by clicking on them, but only when the Contextual ActionBar up.
The problem is that when I check isItemChecked() to toggle the item's selection state, it always returns the opposite of what it should.
This is how I implemented OnItemClickListener :
list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mActionMode != null){ list.setItemChecked(position, !list.isItemChecked(position)); } else{ list.setItemChecked(position, false); } } });
EDIT: This is pretty funny .. this code switches the selection state:
list.setItemChecked(position, list.isItemChecked(position));
What's happening??
EDIT 2: And, it seems, the android automatically checks and removes each element on its own ... is there a way to change this behavior and process it yourself?
android android-listview android-adapterview
Jason powers murray
source share