我正在编写一个简单的脚本,其中有两个选项的确认框。我需要在一项活动中多次调用它。所以我做了一个方法来做到这一点。基于返回的布尔值,我想编写条件语句。
// Before oncreate
static boolean confirmation;
private void showConfirmation() {
// UserFunctions userFunctions = null;
// TODO Auto-generated methodastub
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ProfileActivity.this);
// set title
alertDialogBuilder.setTitle("test");
// set dialog message
alertDialogBuilder.setMessage("Please update the unfilled fields.").setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
confirmation = false;
}
}).setNegativeButton("Later on", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
confirmation = true;
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
@Override
public void myOnClickRecharge(View v) {
showConfirmation();
if (confirmation){
Intent intent = new Intent(getApplicationContext(), NewActivity.class);
startActivity(intent);
}
}