/**
* 第一种弹出对话框的方法,直接在程序中弹出对话框
*/
builder =new AlertDialog.Builder(this); //显示信息
builder.setMessage("直接弹出")
//确定按钮
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
tv.setBackgroundColor(Color.CYAN);
}
})
//取消按钮
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
setTitle("选择取消");
}
});
AlertDialog ad00=builder.create();
ad00.show();
/**
*第二种弹出对话框的方法,调用系统的onCreateDialog方法
**/
showDialog(1);
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
if(id==1){
new AlertDialog.Builder(this)
.setTitle("第二种")
.setMessage("调用系统的onCreateDialog(id)方法")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
tv.setBackgroundColor(Color.CYAN);
}
})
.setNegativeButton("取消", null).show();
}
return super.onCreateDialog(id);
}