samedi 3 décembre 2016

java if statement && string compare

            cipher=txt_cipher.getText().toString();
            StringBuilder msg =  new StringBuilder(txt_msg.getText().toString());
            if (cipher.equals("") || msg.equals("")){
                Toast.makeText(getApplicationContext(), "" + "Please fill all blank spaces !", Toast.LENGTH_SHORT).show();
            }
            else if (cipher.equals("h") && msg.equals("k")){ // HERE !!
                MediaPlayer myMediaPlayer = null;
                myMediaPlayer = MediaPlayer.create(MainActivity.this , R.raw.sound);
                myMediaPlayer.start();
            }
            else{
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(txt_msg.getWindowToken(), 0);
            Toast.makeText(getApplicationContext(), "" + "Copied to clipboard !", Toast.LENGTH_SHORT).show();

My problem is i can't get inside the else if which is commented // HERE !! and i'm pretty sure that i type "h" and "k" i tried to assign a string the "h" and compare that string but it didn't work it didn't get in the else if.

Aucun commentaire:

Enregistrer un commentaire