Wednesday, April 24, 2013

[android help] ListView selection remained after exit from action mode


The following scenario is not uncommon under activity with list view.


  1. Long pressed an item to enter multi-selection mode.

  2. Select the desired item, then press an action button. For example, delete button.

  3. Exit from multi-selection mode (CHOICE_MODE_MULTIPLE) to none-selection mode (CHOICE_MODE_NONE).

I tested the following situation under Android 4.1.


  1. Scroll the list view to the end till "Item 1023" is seen.

  2. Long press on "Item 1023" to enter action mode.

  3. Select "Item 1019" till "Item 1022". Now, total 5 items is selected including "Item 1023"

  4. Scroll up the list, till only the last visible item is "Item 1019"

  5. Pressed delete button on the top right. 6) Scroll up to the top most.

You will realize along the way, certain rows are being selected. It seems that the recycle views's state_activated stage is not being cleared off, when we exit from multi-selection mode.


Even though I have the following code



@Override
public void onDestroyActionMode(ActionMode mode) {
// http://stackoverflow.com/questions/9754170/listview-selection-remains-persistent-after-exiting-choice-mode
// Using View.post is the key to solve the problem.
final ListView listView = MainActivity.this.getListView();
listView.clearChoices();
for (int i = 0, ei = listView.getChildCount(); i < ei; i++) {
listView.setItemChecked(i, false);
}
listView.post(new Runnable() {
@Override
public void run() {
listView.setChoiceMode(ListView.CHOICE_MODE_NONE);
}
});
actionMode = null;
}


It doesn't help much.


Any workaround on this long standing bug?


I include a complete workable code to demonstrate this bug. https://www.dropbox.com/s/t5zgadtz9q61j00/multimode_bug.zip


p/s This is re-post from https://groups.google.com/forum/?fromgroups=#!topic/android-developers/qeJ-bnGUugg



Using MultiChoiceModeListener couple with CHOICE_MODE_MULTIPLE_MODAL will make this bug gone. However, for device below API level 11 will not able to use this solution.



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...