java - android cannot get the text and do the login -
i trying create login page android app. have 2 editview , button. using static user credentials login. when run app, , try login correct username , password, gives incorrect credential message.
here code, simple piece of code
public void sendmessage(view view) { edittext user_name = (edittext)findviewbyid(r.id.txt_username); edittext password =(edittext)findviewbyid(r.id.txt_password); if(user_name.gettext().tostring()=="rotanet" && password.gettext().tostring()=="rotanet"){ intent intent = new intent(this, mainactivity.class); startactivity(intent); textview lbl_error = (textview)findviewbyid(r.id.lbl_error); lbl_error.settext(""); } else{ textview lbl_error = (textview)findviewbyid(r.id.lbl_error); lbl_error.settext("wrong credentials!"); } }
you using == compare strings.
use .equals insted.
if(user_name.gettext().tostring().equals("rotanet") && password.gettext().tostring().equals("rotanet")){
Comments
Post a Comment