ListView selection remains persistent after exiting choice mode

后端 未结 11 865
青春惊慌失措
青春惊慌失措 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:15

    This has been logged as an AOSP bug, but marked as obsolete for whatever reason.

    Normally you would expect this to work:

    getListView().clearChoices();
    getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
    

    Unfortunately it does not. Deferring setting choice mode to none in the next layout pass would work:

    getListView().clearChoices();
    getListView().post(new Runnable() {
        @Override
        public void run() {
            getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
        }
    });
    

提交回复
热议问题