bee*_*ear 8 android android-listview android-alertdialog android-checkbox
我一直试图获得一个列表,其中包含10-12个项目,每个项目在警报对话框中都有一个复选框(即我的活动开始时).到目前为止,我已经提出了以下代码; 它没有复选框.
那么,我该如何实现呢?任何示例代码或建议将不胜感激.
谢谢
final CharSequence[] items = {"cat1","cat2","cat3" };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Categories");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch (item) {
case 0:
//handle item1
break;
case 1:
//item2
break;
case 2:
//item3
break;
default:
break;
} }
});
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud)
您必须在构建器对象中设置setSingleChoiceItems()方法而不是如下所示的setItems.
builder.setSingleChoiceItems(items , -1,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}
})
Run Code Online (Sandbox Code Playgroud)
如果要显示多个选择列表对话框,则必须在其参数中使用DialogInterface.OnMultiChoiceClickListener设置setMultiChoiceItems()而不是setSingleChoiceItems
在Developer.Android.com中提到所有内容,您可以在此处查找对话框帮助
| 归档时间: |
|
| 查看次数: |
5803 次 |
| 最近记录: |