I\'d like to clear selected items when the total came to three items selected, I am doing as follows but is not working ...
AlertDialog.Builder builder = new
if you want to use multicheckoption as single selection option then use this code.
String[] items = new String[]{"Most Funded (high - low)", "Most Funded (low - high)", "Newest first", "Funding Ask"};
boolean selected[] = new boolean[]{false, false, false, true};
private void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getResources().getText(R.string.sortby));
builder.setMultiChoiceItems(items, selected, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
//
for (int i = 0; i < selected.length; i++) {
if (i == which) {
selected[i]=true;
((AlertDialog) dialog).getListView().setItemChecked(i, true);
}
else {
selected[i]=false;
((AlertDialog) dialog).getListView().setItemChecked(i, false);
}
}
}
});
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.show();
}