开发者

condition and EditText

I want to go to another activity if the login and password are ok. I can't understand why it execute the else block, the condition is never true! even if I enter the good login and password. When I did my tests, I can say that the problem is in the conversion from EditText to String but I don't开发者_开发知识库 know how to do it in a different way.

This is the code:

 public void onClick(DialogInterface dialog, int which) {

//Lorsque l'on cliquera sur le bouton "OK", on récupère l'EditText correspondant à notre vue personnalisée (cad à alertDialogView)
           EditText et1 = (EditText)alertDialogView.findViewById(R.id.EditText1);
           EditText et2 = (EditText)alertDialogView.findViewById(R.id.EditText2);
                String A = et1.getText().toString();
                String B = et2.getText().toString();

                if ((A=="tao") && (B=="ensi"))
                {
 Toast.makeText(Main.this, "athentif effectuer avec succé", Toast.LENGTH_SHORT).show();
 setContentView(R.layout.admin);                     
                }

                else

                {
                    DemoAlertDialog();
//On affiche dans un Toast le texte contenu dans l'EditText de notre AlertDialog
Toast.makeText(Main.this, "veuillez verifier vos donnés",Toast.LENGTH_LONG).show();


                }


you are using == to compare strings which is incorrect.

You should use :

    if (A.Equals("tao") && B.equals("ensi") {

    }


I found the solution.

I forgot to use the method contains of the string. This is what should be used:

if (A.contains("tao") && B.contains("ensi")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜