java - check empty edit text in an alert dialog android -
i have following code checking empty edit text in alert dialog, not working
if (mphonenumber == null) { mphonenumber = getnumber(); if (mphonenumber == "error") { final alertdialog.builder alert = new alertdialog.builder(this); alert.settitle("warrning"); alert.setmessage("please set phone number"); final edittext input = new edittext(this); input.setinputtype(inputtype.type_class_phone); alert.setview(input); alert.setpositivebutton("ok",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int whichbutton) { string value = input.gettext().tostring(); while (value.isempty()) { alert.settitle("warrning"); alert.setmessage("please set phone number"); alert.setview(input); alert.setpositivebutton("ok",new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog,int whichbutton) { string value = input.gettext().tostring();}}); } string result = setnumber(value); mphonenumber = value; int userserviceid = calllogin(mphonenumber); if (userserviceid > 0) { intent service = new intent(mainscreeen.this, recipeservice.class); service.putextra("userid", userserviceid); startservice(service); } else { intent reg = new intent(mainscreeen.this,regsteration.class); reg.putextra("phonenumber", mphonenumber); startactivity(reg); } } }); alert.show();
i need enforce user inter his/her phone number , not leaving edit text being empty, used while loop not working
it looks trying compare string
values. can't this
if (mphonenumber == "error")
change to
if("error".equals(mphonenumber))
==
compares if same object strings
not if have same value. doing way shouldn't need null
check because "error" won't equal mphonenumber
if mphonenumber
null
Comments
Post a Comment