对话框的几种常见方式:
* 创建一般对话框
AlertDialog alertDialog = new Builder(this).setTitle("提示") .setMessage("您确定退出该应用吗?").setPositiveButton("确定",null)
setNegativeButton("取消",null).create();
alertDialog.show();
* 创建单选多选对话框
final String[] fruits = new String[] {"苹果", "西瓜", "哈密瓜", "梨" };
new Builder(this).setTitle("请输入您喜欢的水果").setSingleChoiceItems(fruits, 0,null).show();
final String[] fruits = new String[] {"苹果", "西瓜", "哈密瓜", "梨" };
final boolean[] fruitsCheck = new boolean[] { true, false, true, false };
new Builder(this).setTitle("请输入您喜欢的水果") .setMultiChoiceItems(fruits,fruitsCheck,null).setPositiveButton("确定", null).show();
* 创建带进度的对话框
final ProgressDialog dialog=new ProgressDialog(this);
dialog.setTitle("提示");
dialog.setMessage("正在拼命加载,请耐心等待...");
dialog.show();
new Timer().schedule(new TimerTask() {
@Override
publicvoid run() {
dialog.dismiss();
}
}, 3000);
网友评论