我创建了带复选框的Multiselect微调器但是如果没有从微调器中选择任何内容我点击'确定'然后显示吐司请给出解决方案
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (mSelection != null && which < mSelection.length) {
mSelection[which] = isChecked;
simple_adapter.clear();
simple_adapter.add(buildSelectedItemString());
} else {
throw new IllegalArgumentException(
"Argument 'which' is out of bounds.");
}
}
@Override
public boolean performClick() {
final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMultiChoiceItems(_items, mSelection, this);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
builder.show();
return true;
}
答案 0 :(得分:0)
您可以使用以下代码行在对话框按钮单击侦听器
上显示吐司 CharSequence[] items={"One","Two"};
boolean isAnyCheckboxTick=false;
AlertDialog.Builder builder =
new AlertDialog.Builder(context);
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
isAnyCheckboxTick=true;
}
});
builder.setPositiveButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(!isAnyCheckboxTick)
Toast.makeText(context,"Ok Clicked",Toast.LENGTH_LONG).show();
}
});
builder.show();