I have created an AlertDialog with OnMultiChoiceClickListener,I wants to uncheck checkbox when the user selects 4th option i.e I wants the user to select only 3 items.
code:
protected void showSelectColoursDialog() {
boolean[] checkedColours = new boolean[colours.length];
int count = colours.length;
for(int i = 0; i < count; i++)
checkedColours[i] = selectedColours.contains(colours[i]);
DialogInterface.OnMultiChoiceClickListener coloursDialogListener = new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// ((AlertDialog) dialog).getListView().setItemChecked(which,false);
if(selectedColours.size()>2){
// Here I wants to uncheck Checkbox,but the below line is not working for me.
((AlertDialog) dialog).getListView().setItemChecked(which,false);
alertMessage();
}
else{
if(isChecked)
selectedColours.add(colours[which]);
else
selectedColours.remove(colours[which]);
}
onChangeSelectedColours();
}
};