下面代码将打开一个如右下图所示的多选项列表对话框:
final String[] items = {"java", ".net", "php"};
new AlertDialog.Builder(SenderNotificationActivity.this).setCancelable(false)
.setTitle("选择语言")
.setMultiChoiceItems(items, new boolean[]{false,true,false}, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if(isChecked){
Toast.makeText(getApplicationContext(), items[which],
Toast.LENGTH_SHORT).show();
}
}
})
.setPositiveButton("确认",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialoginterface, int i){
dialoginterface.dismiss();
}
})
.show();//显示对话框