0

我有一个登录页面。当用户正确登录时,我想显示一个警告对话框,说明您的登录详细信息已经过验证。单击继续继续。现在我希望在登录后的下一个活动页面上显示此警告对话框. 这是警报对话框代码-:

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();  
              }
            });
4

3 回答 3

0

实际上无法解决更多问题,但是您想AlertDialog在某些情况下显示您的信息,Optionnale Requirement例如何时Login显示,而在下一页中,Required但由于SharedPreferences 在应用程序启动时仅显示一次。当我注销然后登录时,我没有得到任何alert dialog

SharedPreferences 要做的是用密钥存储您的特定 Sting,您需要与之匹配。成功后,您需要Update SharedPreferences使用一些新字符串并需要与之匹配。

您也可以使用File检查isExit()与否并编写 require Sting 它并阅读它并匹配您需要显示的条件alert dialog。这可能会帮助你。

于 2013-04-09T07:28:29.443 回答
0

跟踪活动流程,即当您启动应用程序时,它正在执行 onCreate 方法中的操作,为您的问题在 on create 方法中设置标志,并且当您从任何其他活动切换到此活动时,请执行 onCreate 方法重新启动()并清除您以前的数据....像这样...

protected void onRestart() {
    // TODO Auto-generated method stub
    super.onRestart();

    //ur code
}

希望它会有所帮助,

于 2013-04-09T07:32:00.010 回答
0

您需要在当前代码中添加一些实现。
您可以在 sharedPrefs 中保留一个标志,最初它是正确的。在第一次展示它之后,让它成为假的。
这是您现在必须实施的。

因此,当用户注销时,要在注销后再次显示它,将标志重置为 true。因此,当您再次到达活动时,将显示对话框。

于 2013-04-09T07:17:08.183 回答