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
You can use below ways for multiple selection and can use samples also:
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).
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);
}
}