android - optionsmenu both cases execute -
in login activity i've created 2 button s on options menu, login , change user. if user clicks change user data deleted phone. display dialog box asking user confirm action.
it seems work fine until user logs out once doesn't enter credentials in username , password textviews. if these empty when user clicks login button toast message displays showing 'please enter valid name' dialog box displays asking if user wants change user.
my question why dialog box display asks user confirm want change user when code not in login case within options menu? when user clicks login empty fields change user code executes. in advance matt.
@override public boolean onoptionsitemselected(menuitem item) { cursor allfromcompidtable = nfcscannerapplication.loginvalidate.queryallfromcompanyidtable(); if(allfromcompidtable.getcount() > 0){ if(allfromcompidtable.movetolast()){ compid = allfromcompidtable.getstring(allfromcompidtable .getcolumnindex(loginvalidate.c_company_id_outside_app_purposes)); } } if(isallowchangeuser.equalsignorecase("false")){ if(item.getitemid() == r.id.changeuser) item.setvisible(false); } switch (item.getitemid()) { case r.id.login: log.e(tag, "login clicked opts menu"); theusername = username.gettext().tostring(); if(theusername.trim().equalsignorecase("")){ toast.maketext( entryactivity.this, "please enter valid name.", toast.length_long).show(); oncreate(sis); }else{ thepassword = passwordpin.gettext().tostring(); string logintype = "1"; if(issavepassword.trim().equalsignorecase("false")){ if( ! thepassword.trim().equalsignorecase("")){ string[] params = new string[]{compid, theusername, thepassword, logintype}; //validate user asynchonously on background thread asyncvalidatecarer avc = new asyncvalidatecarer(); avc.execute(params); }else{ toast.maketext( entryactivity.this, "please enter valid password.", toast.length_long).show(); } }else if(issavepassword.trim().equalsignorecase("true")){ cursor c = nfcscannerapplication.loginvalidate.queryallfromcarer(); string firstnamefromdb = null; string passwordfromdb = null; string careridfromdb = null; if(c != null && c.getcount() > 0){ c.movetolast(); firstnamefromdb = c.getstring(c.getcolumnindex(loginvalidate.c_carer_firstname)); passwordfromdb = c.getstring(c.getcolumnindex(loginvalidate.c_password)); careridfromdb = c.getstring(c.getcolumnindex(loginvalidate.c_carer_id)); carerid = careridfromdb; }else{ string[] params = new string[]{compid, theusername, thepassword, logintype}; //validate user asynchonously on background thread asyncvalidatecarer avc = new asyncvalidatecarer(); avc.execute(params); } if(theusername.trim().equalsignorecase(firstnamefromdb) && thepassword.trim().equalsignorecase(passwordfromdb)){ intent intent2 = new intent(entryactivity.this, nfcscanneractivity.class); intent2.setaction(custom_qrcode_action); intent2.putextra("carerid", carerid); startactivity(intent2); } } return true; } case r.id.changeuser: alertdialog.builder alertdialogbuilder = new alertdialog.builder(this); alertdialogbuilder.setmessage("are sure want change user? call history , messages deleted.") .setcancelable(false) .setpositivebutton("ok", new dialoginterface.onclicklistener(){ public void onclick(dialoginterface dialog, int id){ log.e(tag, "change user button clicked"); nfcscannerapplication.loginvalidate.deletetablecarer(); nfcscannerapplication.loginvalidate.deletetabletransactions(); toast.maketext( entryactivity.this, "carer logged out", toast.length_long).show(); entryactivity.this.oncreate(sis); } }); alertdialogbuilder.setnegativebutton("cancel", new dialoginterface.onclicklistener(){ public void onclick(dialoginterface dialog, int id){ } }); alertdialog alert = alertdialogbuilder.create(); alert.show(); return true; default: return super.onoptionsitemselected(item); } }
add
break;
at end of each item of switch.
Comments
Post a Comment