Question: I am giving array to select multiple options through alert dialog I want to disable selection if array is full

I have been able to stop adding items to array after it reaches the limit but not able to disable the checkboxes

```
 AlertDialog.Builder builder=new AlertDialog.Builder(this);
 View view=inflater.inflate(R.layout.dialog_genre,null,false);
 builder.setView(view).setTitle("Select Genres");

 builder.setMultiChoiceItems(array, checkedGenres, new DialogInterface.OnMultiChoiceClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            if(isChecked) {
                if (!selectedgenre.contains(String.valueOf(which)))
                    if(selectedgenre.size()<5)
                {
                    selectedgenre.add(String.valueOf(which));
                    checkedGenres[which]=true;
                }
                else{
                        Toast.makeText(getApplicationContext(),"you can't add more genres",Toast.LENGTH_LONG).show();
                    }
            }
            else if (selectedgenre.contains(String.valueOf(which)))
            {
             selectedgenre.remove(String.valueOf(which));
             checkedGenres[which]=false;
        }
    }
}

```

[![enter image description here](https://i.stack.imgur.com/OWJDD.png)](https://i.stack.imgur.com/OWJDD.png)

Answer: 
```
   builder.setMultiChoiceItems(array, checkedGenres, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                if(isChecked) {
                    if (!selectedgenre.contains(String.valueOf(which)))
                        if(selectedgenre.size()<5)
                    {
                        selectedgenre.add(String.valueOf(which));
                        checkedGenres[which]=true;
                    }
                    else{
                        //set your checkbox to false here
                        //yourCheckbox.setchecked(false); 
                            Toast.makeText(getApplicationContext(),"you can't add more genres",Toast.LENGTH_LONG).show();
                        }
                }
                else
                {
                 selectedgenre.remove(String.valueOf(which));
                 checkedGenres[which]=false;
            }
        }
    }

```

Try with this.. issue in your else part
In your else part put clickable false on your checkbox and also change the color so that user can identify it.