samedi 25 juillet 2015

if-else block not working properly in android

Scenario is, when focus is lost from EditText, im checking if it contains null (in the first if block) if yes, then showing a toast, in the else-if block im checking if EditText doesn't contains letters then showing a toast, but when i run the application toast is shown even on correct input i.e. If i enter any letter toast should not be shown, it should be shown only when null or digit/special symbol is entered.here is the code below

et1.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // TODO Auto-generated method stub
            if(!hasFocus)
            {
                a = et1.getText().toString();
                if (a == "")
                {
                    Toast.makeText(getApplicationContext(), "Your entry is incorrect!!", Toast.LENGTH_LONG).show();
                }
                else if (!a.contains("[a-z]")||!a.contains("[A-Z]")) {
                    Toast.makeText(getApplicationContext(), "Your entry is incorrect!!", Toast.LENGTH_LONG).show();

                }
                else
                {
                }

Please help,, Thankyou

Aucun commentaire:

Enregistrer un commentaire