ListView selection remains persistent after exiting choice mode

后端 未结 11 842
青春惊慌失措
青春惊慌失措 2020-11-29 01:45

I have a ListView subclass that I allow selections on when the context action bar (CAB) is active. The CAB is set as a callback to the onItemLongClick event:

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 02:18

    I faced the same issue and since requesting layout doesn't solve the problem for me either I implemented a little hack which works for me. Maybe this is the same issue because I'm switching between CHOICE_MODE_SINGLE and CHOICE_MODE_NONE.

    When the action mode ends I'm calling this code snippet. clearChoices makes sure that all items are not checked anymore (internally). The iteration over the views makes sure that all currently visible views are reset and not checked anymore.

    mListView.clearChoices();
    
    for (int i = 0; i < mListView.getChildCount(); i++) {
        ((Checkable) mListView.getChildAt(i)).setChecked(false);
    }
    
    mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
    

提交回复
热议问题