mercredi 14 septembre 2016

edittext.gettext().tostring().isempty() condition executing even when there is text in the EditText?

I'm trying to do something like this: I'm trying to check if there is text is the EditText using gettext().tostring().isempty(). If there is no text, a Snackbar will be shown and if there is some text, another method will get executed.

Here's the code:

final AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
            builder.setTitle("Choose a unique username");
            builder.setView(R.layout.choose_unique_name_dialog);
            builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (uniqueUserName.getText().toString().isEmpty()) {
                        Snackbar snackbar = Snackbar
                                .make(coordinatorLayout, "Please choose a unique username", Snackbar.LENGTH_SHORT);
                        snackbar.show();
                    } else {
                        signingUpMethod();
                    }
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();

The problem is that either times (when edittext is empty and filled) the snackbar is getting shown. I don't know why is this happening!!

Please let me know.

Aucun commentaire:

Enregistrer un commentaire