如果条件没有检查android,否则在其他内部

时间:2015-06-03 10:23:15

标签: android if-statement

嗨,在下面的代码里面,如果条件里面没有检查用户名和密码是否与直接找到的管理员用户匹配它只检查是否在那之后是否正在检查。但是在if条件下的其他内容没有进行。< / p>

的java

else{

        queryString = "username=" + username + "&password="
                + password ;
        String usertype = DatabaseUtility.executeQueryPhp("login",queryString);
        System.out.print(usertype);

        if(usertype.equalsIgnoreCase("Admin user Found")){

            runOnUiThread(new Runnable() {

                public void run(){

                    Toast.makeText(Login.this, "Login Sucess",
                       Toast.LENGTH_LONG).show();           

               }
        });

        Intent in=new Intent(Login.this, Reports.class);
        startActivity(in);

    }


    else if(usertype.equalsIgnoreCase("No User Found")){

        runOnUiThread(new Runnable() {

             public void run() {     

                 tv2.setText("InValid UserName and Password");

             }

        });
    }

}

2 个答案:

答案 0 :(得分:1)

为什么不使用else代替else if ??? 问题不在于java,
调试应用并检查变量userType的值,它会有所不同 如果您无法调试,您可以显示吐司以检查其值。

   if (!isInternetPresent) {
        showAlertDialog(Login.this, "No Internet Connection",
                "You don't have internet connection.", true);

        return;


    }
    //// If Condition Finishes


    String username = usname.getText().toString();
    String password = pword.getText().toString();

    // String name = user.get(SessionManager.KEY_USERNAME);


    if (username.equals("")) {
        Toast.makeText(Login.this, "ENTER USERNAME",
                Toast.LENGTH_LONG).show();

    }
    //// If Condition Finishes


    if (password.equals("")) {
        Toast.makeText(Login.this, "ENTER PASSWORD",
                Toast.LENGTH_LONG).show();

    }
    //// If Condition Finishes

    else if (!CheckUsername(username) && !CheckPassword(password)){
        Toast.makeText(Login.this, "ENTER VALID USERNAME & PASSWORD",
                Toast.LENGTH_LONG).show();
    }
    //// Else If Condition Finishes

    else{
        queryString = "username=" + username + "&password="
                + password ;
        String usertype = DatabaseUtility.executeQueryPhp("login",queryString);
        System.out.print(usertype);

        if(usertype.equalsIgnoreCase("Admin user Found")){
            runOnUiThread(new Runnable() {
                public void run() {

                    Toast.makeText(Login.this, "Login Sucess",
                            Toast.LENGTH_LONG).show();


                }
            });


            Intent in=new Intent(Login.this, Reports.class);
            startActivity(in);

        }
        //// If Condition Finishes



        //// I Suppose this is the else if you are talking about
        else if(usertype.equalsIgnoreCase("No User Found")){
            runOnUiThread(new Runnable() {
                public void run() {


                    tv2.setText("InValid UserName and Password");

                }

            });
        }
        //// Else If Condition Finishes

    }
    //// Else Condition Finishes  

我希望它有所帮助 祝你好运:)

答案 1 :(得分:0)

如果您的以下if块无法正常工作

**

  

if(usertype.equalsIgnoreCase(“Admin user Found”)){

**

然后它的意思是你的“usertype”不等于“Admin user Found”。

看似简单