问题描述
- 安卓dialog复选框如何获取勾选的数据?
-
private void fuXuanKuang() { final String[] items = { "Item1", "Item2" }; AlertDialog.Builder builder = new Builder(MainActivity.this); builder.setIcon(android.R.drawable.ic_dialog_info); builder.setTitle("复选框"); builder.setMultiChoiceItems(items, new boolean[] { true, false }, new OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { } } }); builder.setPositiveButton("确认", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT) .show(); } }); builder.setNegativeButton("取消", null); Dialog dialog = builder.create(); dialog.show(); }
解决方案
定义一个Items等长的数组arrSelect
然后
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
arrSelect[which]=isChecked;
}
解决方案二:
dialog选中状态时 可以吧items 【i】数据选中处理
时间: 2024-12-20 19:31:31