1.单选对话框
private String[] arr = {"aaa","bbb","ccc","ddd"};
public void singleListAlertDialog(View view){
new AlertDialog.Builder(this)
.setTitle("单项列表对话框")
.setSingleChoiceItems(arr,0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"您选择了:"+arr[which],Toast.LENGTH_LONG).show();
}
})
.show();
}
2.多选对话框
public void create(){
dialog = new AlertDialog.Builder(this)
.setTitle("复选列表对话框")
.setMultiChoiceItems(arr, new boolean[]{true, false, true, false}, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
}
})
.create();
}
// 点击弹出多选框
public void mutiListAlertDialog(View view){
dialog.show();
}