Android comparing strings with == to each objects -
i'm coming c#, typically try relate i'm doing.
i cannot figure out why below statement doesn't work. string val = "admin". have if statement, if statement false. i'm sure it's simple.
thanks!
edittext edt = (edittext) findviewbyid(r.id.email); //string val = edt.gettext().tostring(); string val = "admin"; edittext edt2 = (edittext) findviewbyid(r.id.password); string val2 = edt2.gettext().tostring(); if(val.tostring() == "admin") { string hero = val; }
you should use
if (val.equals("admin")) { string hero = val; }
instead of using equal sign. using equal sign in java asking if they're same object, false if strings same.
also, careful you're doing inside of if statement, because variable "hero" won't accessible outside of block.
Comments
Post a Comment