Max selectable count for “CHOICE_MODE_MULTIPLE_MODAL” gridview

前端 未结 3 1982
终归单人心
终归单人心 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:24

    You can use below ways for multiple selection and can use samples also:

    1. https://github.com/ManuelPeinado/MultiChoiceAdapter
    2. https://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-select-multiple/
    3. https://github.com/derosa/MultiImageChooser
    4. https://github.com/luminousman/MultipleImagePick
    0 讨论(0)
  • 2021-01-27 17:29

    Use getCheckedItemCount() method to check the count on gridview's item select listener and check if count greater than max value

    public int getCheckedItemCount ()

    Returns the number of items currently selected. This will only be valid if the choice mode is not CHOICE_MODE_NONE (default).

    0 讨论(0)
  • 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);                       
            }
    
      }
    
    0 讨论(0)
提交回复
热议问题