Max selectable count for “CHOICE_MODE_MULTIPLE_MODAL” gridview

前端 未结 3 1983
终归单人心
终归单人心 2021-01-27 16:55

I created a Gridview with CHOICE_MODE_MULTIPLE_MODAL in Android.

Everything\'s working well. But as per requirements, I have to set a limit for selecta

3条回答
  •  鱼传尺愫
    2021-01-27 17:31

    In order to deselect the current item in a multiple Choice gridview, you can use the following in the onItemCheckedStateChanged() of the GridView.MultiChoiceModeListener:

     @Override
        public void onItemCheckedStateChanged(ActionMode actionMode, int position, long id, boolean checked) {
    
            if(gridView.getCheckedItemCount() > numberOfSelectionsAllowed ){                       
                gridView.setItemChecked(position, false);                       
            }
    
      }
    

提交回复
热议问题