The following scenario is not uncommon under activity with list view.
- Long pressed an item to enter multi-selection mode.
- Select the desired item, then press an action button. For example, delete button.
- Exit from multi-selection mode (CHOICE_MODE_MULTIPLE) to none-selection mode (CHOICE_MODE_NONE).
I tested the following situation under Android 4.1.
- Scroll the list view to the end till "Item 1023" is seen.
- Long press on "Item 1023" to enter action mode.
- Select "Item 1019" till "Item 1022". Now, total 5 items is selected including "Item 1023"
- Scroll up the list, till only the last visible item is "Item 1019"
- 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?
- ListView selection remains persistent after exiting choice mode
- https://groups.google.com/forum/?fromgroups=#!topic/android-developers/TDG9-yP5ddg Is this being reported in Android bug ticketing? Thanks.
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