为“是”和“否”创建一个完整的对话框。请执行下列操作:
注意:对于此代码,您将需要一个按钮。
希望能帮助到你。
按钮按钮 = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder.setTitle("Alert");
alertDialogBuilder.setMessage("Do you really want to exit?");
AlertDialog.Builder ad = new AlertDialog.Builder(MainActivity.this);
ad.setCancelable(false);
ad.setTitle("EXIT CONFIRMATION");
ad.setMessage("are you sure you want to exit?");
ad.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
finish();
}
});
ad.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
ad.show();
}
});