private void showNormalDialogOne() {
/* @setIcon 设置对话框图标
* @setTitle 设置对话框标题
* @setMessage 设置对话框消息提示
* setXXX方法返回Dialog对象,因此可以链式设置属性
*/
final AlertDialog.Builder normalDialog = new AlertDialog.Builder(this);
normalDialog.setTitle("提示");
normalDialog.setMessage("确定删除所有!");
normalDialog.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// delehistory();//dosomething
}
});
normalDialog.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
normalDialog.show();
}
单选项dialog
AlertDialog.Builder builder = new AlertDialog.Builder(SynthActivity.this, android.R.style.Theme_Holo_Light_Dialog);
builder.setTitle("引擎空闲时切换");
final Map map = new LinkedHashMap<>(4);
map.put("离线女声", OfflineResource.VOICE_FEMALE);
map.put("离线男声", OfflineResource.VOICE_MALE);
map.put("离线度逍遥", OfflineResource.VOICE_DUXY);
map.put("离线度丫丫", OfflineResource.VOICE_DUYY);
final String[] keysTemp = new String[4];
final String[] keys = map.keySet().toArray(keysTemp);
builder.setItems(keys, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
loadModel(map.get(keys[which]));
Log.i("lgq","....."+map.get(keys[which]));
}
});
builder.show();
2、多选项dialog
private String[] favor = {"美容 ", "汽车 ", "游戏 ", "社交 ", "体育 ", "阅读 ",
"影视 ", "母婴 ", "健康 ", "家居 ", "服饰 ", "其他 "};
private String hobby;
private int befoid;
//兴趣爱好设置
private void hobbySetting() {
AlertDialog.Builder dialogm = new AlertDialog.Builder(this);
dialogm.setMultiChoiceItems(favor, new boolean[]{false, false, false, false, false, false, false, false, false, false, false, false},
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (!TextUtils.isEmpty(hobby)&&hobby.split("\\ ").length > 2&&befoid!=which) {
// ToastUtil.centralToast("最多只能选择3项", mContext);
dialog.dismiss();
hobby = "";
befoid = 99;
} else {
if (isChecked){
hobby = hobby + favor[which];
befoid = which;
Log.v("lgq","兴趣爱好。。。。。-====="+hobby);
}
else {
hobby = hobby.replace(favor[which], "");
befoid = 99;
Log.v("lgq","兴趣爱好。。。else。。==="+hobby);
}
}
}
});
dialogm.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (hobby.equals("")) tvHobby.setText("未设置");
else tvHobby.setText(hobby);
hobby = "";
}
});
dialogm.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialogm.show();
}