Search code examples
androidif-statementandroid-edittextcase-sensitive

EditText case sensitive


    et = (EditText) findViewById(R.id.editText1);
    iv = (ImageView) findViewById(R.id.imageView1);
 Case R.id.ibGo:
    String str = et.getText().toString();
        if (str.contentEquals("password")){
            Intent levelTwo = new Intent (
                "com.xxx.xxx.LEVELTWO");
            startActivity(levelTwo);
        } else if (str.contentEquals("music")){

            Intent levelFour = new Intent (
                "com.xxx.xxx.LEVELFOUR");
            startActivity(levelFour);  
        } else {
            vib.vibrate(300);
            iv.setVisibility(View.VISIBLE);
        }
        break;

When i write "password" in the edittext in the emulator, the emulator works as expected. But when i (for example) write "Passwords"(Capital P) the application stops unexpectedly.

What can I do to make it not fail on capital letters?


Solution

  • Strings are case sensitive.

    Instead of

    if (str.contentEquals("password")){
    //do something
    }
    

    DO THIS!!

    if (str.equalsIgnoreCase("password")){
    //do something
    }