builder=newBuilder(MainActivity.this);builder.setIcon(android.R.drawable.ic_dialog_info);builder.setTitle("dialg标题");//builder.setMessage("dialog对话框内容");builder.setPositiveButton("Yes",newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){// TODO Auto-generated method stub}});// builder.setNeutralButton("back", new OnClickListener() {// // @Override// public void onClick(DialogInterface dialog, int which) {// // TODO Auto-generated method stub// // }// });builder.setNegativeButton("No",newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){// TODO Auto-generated method stub}});builder.setView(newCheckBox(this));builder.show();
由于 Builder 设计模式特性,上面代码也可以这样简写
1234567891011121314151617181920212223
newBuilder(this).setIcon(android.R.drawable.ic_dialog_info).setTitle("dialg标题").setMessage("dialog对话框内容").setPositiveButton("yes",newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){// TODO Auto-generated method stub}}).setNegativeButton("no",newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){// TODO Auto-generated method stub}}).setView(newCheckBox(this)).create().show();
builder.setView(new CheckBox(this));只能添加一个组件
如果添加多个组件,会被后面的覆盖掉
添加某些一组组件,还有对应函数
添加单选框
12345678
builder.setSingleChoiceItems(newString[]{"单选","单选"},1,newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialog,intwhich){// TODO Auto-generated method stub}});
添加复选框
12345678
builder.setMultiChoiceItems(newString[]{"多选","多选"},newboolean[]{false,true},newOnMultiChoiceClickListener(){@OverridepublicvoidonClick(DialogInterfacearg0,intarg1,booleanarg2){// TODO Auto-generated method stub}});
添加列表
12345678
builder.setItems(newString[]{"item1","item2","item3"},newOnClickListener(){@OverridepublicvoidonClick(DialogInterfacearg0,intarg1){// TODO Auto-generated method stub}});