if statement - If else condition not working on button click in Android -
if don't use condition on click call activity works, when use condition not responding, neither calling if
section nor else
:
btnupload.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // uploading file server try { strgetname = pref.getstring("key_name", null); strgetemail = pref.getstring("key_email", null); if (strgetemail.equals("")&&strgetname.equals("")) { toast.maketext(uploadactivity.this, "please create account first", toast.length_short).show(); intent intent = new intent(uploadactivity.this, basicactivity.class); startactivity(intent); } else { new uploadfiletoserver().execute(); } } catch (exception e) { // todo: handle exception } } });
there should space between && , strgetname.equals("") in if condition.
if (strgetemail.equals("") && strgetname.equals(""))
and change
strgetname = pref.getstring("key_name", null); strgetemail = pref.getstring("key_email", null);
to
strgetname = pref.getstring("key_name", ""); strgetemail = pref.getstring("key_email", "");
Comments
Post a Comment