我正在尝试创建一个具有多选选项的AlertDialog。我尝试使用setMultiChoiceItems
,但我有一个ArrayList<Category>
而不是CharSequence
,所以我尝试使用适配器。
setAdapter
的问题在于当我选择一个项目时它会关闭对话框窗口。我想要的是选择项目,然后点击“确定”按钮查看被选中的项目。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
ArrayAdapter<Category> catsAdapter = new ArrayAdapter<Category>(this, android.R.layout.select_dialog_multichoice,this.categories);
builder.setAdapter(catsAdapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
}
});
builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do something
}
});;
AlertDialog alert = builder.create();
alert.show();