How to check EditText isEmpty in Android -


i want create login page, used edittext insert user info. want check edittext see if empty invisible login button, when inserted character user visible login button.
tried code shown below, did not not work me :

//show login button string login_phonestring = login_phonetext.gettext().tostring().trim(); if (login_phonestring.isempty()) {     login_image.setvisibility(view.invisible); } else {     login_image.setvisibility(view.visible); } 

when edittext empty, button invisible, , when set character in edittext again login button not shown.

how can fix problem ?

you want show/hide login button base on text of edittext need listen changing in edittext use textwatcher.
use code inside oncreate() method

login_phonetext.addtextchangedlistener(new textwatcher() {          public void aftertextchanged(editable s) {             string login_phonestring = login_phonetext.gettext().tostring().trim();             if (login_phonestring.isempty()) {                 login_image.setvisibility(view.invisible);             } else {                 login_image.setvisibility(view.visible);             }         }         public void beforetextchanged(charsequence s, int start, int count, int after) {}          public void ontextchanged(charsequence s, int start, int before, int count) {} }); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -