android - TextInputLayout issue at Login time -


i have textinputlayout in login, when click on login button if username empty show error same password when password empty show error if username empty , password non empty @ time error not shown how can solve problem? code below!!!

@override public void onclick(view v) {     intent mintent;     switch (v.getid()) {         case r.id.txtsignin:             hidekeyboard(mactivity, v);              if (etusername.gettext().tostring().equals("")) {                 etusername.requestfocus();                 etusername.setcursorvisible(true);                 tilpassword.seterrorenabled(false);                 tilusername.seterrorenabled(true);                 tilusername.seterror(getstring(r.string.username_required));             } else if (etpassword.gettext().tostring().equals("")) {                 etpassword.requestfocus();                 etpassword.setcursorvisible(true);                 tilusername.seterrorenabled(false);                 tilpassword.seterrorenabled(true);                 tilpassword.seterror(getstring(r.string.password_required));             } else {                 tilusername.seterrorenabled(false);                 tilpassword.seterrorenabled(false);                 showtoast(mactivity, getstring(r.string.successfully_login), 0);                 mintent = new intent(signin.this, dashboard.class);                 startactivity(mintent);             }             break;         case r.id.txtsignup:             mintent = new intent(mactivity, signup.class);             startactivity(mintent);             break;         case r.id.txtforgotpassword:             mintent = new intent(mactivity, forgotpassword.class);             startactivity(mintent);             break;     }     try {     } catch (exception e) {         logd(getclass().getsimplename(), e.getmessage());         loge(getclass().getsimplename(), e.getmessage());     } } 

use isempty() method since null , "" <- not equal cannot derive if edittext empty or not .

something below pop error on screen either password or username field empty

if (etusername.isempty() && etpassword.isempty()) {           <your code if nothing entered> } 

for additional check out : check if edittext empty.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo