我有一个登录页面。当用户正确登录时,我想显示一个警告对话框,说明您的登录详细信息已经过验证。单击继续继续。现在我希望在登录后的下一个活动页面上显示此警告对话框. 这是警报对话框代码-:
SharedPreferences 设置 = getSharedPreferences(PREFS_NAME, 0); boolean dialogShown = settings.getBoolean("dialogShown", false);
if (!dialogShown) {
AlertDialog.Builder builder = new Builder(Myperwallet.this);
builder.setTitle("Fast Cashier!");
builder.setMessage("Logging In");
builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
//continue activity here....
}
});
builder.create().show();
// AlertDialog code here
}
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("dialogShown", true);
editor.commit();
我试过这个,但现在我注销后不会显示警告对话框。我需要知道当我按下注销按钮时如何将标志设置为 true。这是我的注销按钮功能-:
logout.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
AlertDialog alertDialog = new AlertDialog.Builder(Myperwallet.this).create();
alertDialog.setTitle("FastCashier:");
alertDialog.setMessage("Are you sure you want to exit?");
alertDialog.setButton( Dialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent logout = new Intent(Myperwallet.this,Login.class);
startActivity(logout);
}
});
alertDialog.setButton( Dialog.BUTTON_NEGATIVE, "NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
});