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;
}
}
}
In your else part put clickable false on your checkbox and also change the color so that user can identify it.
Try with this.. issue in your else part
okay I have solved the issue, after two days I came to know disabling checkbox is lengthy and hectic process but we can prohibit the selection, and that's what I wanted to do. here is my solution
Views inside a ListView are reusable, so items aren't really linked to a view. You can however enable or disable a view when it's being added to the ListView inside your AlertDialog's ListView. ViewGroup.setOnHierarchyChangeListener lets you to do so.
Note that
setEnable
won't avoid clickListeners to trigger. If you don't want to get your checkbox clicked addchild.setOnClickListener(null)
.