android - change the state of toggle on correct password and dismiss the dialog -
in application,i need off toggle if password correct else should on always. showing dialog box asking password on setoncheckedchangelistener, , change state of toggle if password correct.
my problem toggle changes state shows dialog again. dialog should dismiss if password correct ,same time state of toggle should change off. how solve this.
my code:
onoffswitch.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(iscorrectpin) { onoffswitch.setchecked(false); } log.v("switch state=", ""+ischecked); if(ischecked) { //tv_switch_status.settext(""); } else { displaypinalert(); } } }); private void displaypinalert() { onoffswitch.setchecked(true); alertdialog.builder alert = new alertdialog.builder(activity.getparent()); alert.setmessage("enter pin"); // set edittext view user input final edittext input = new edittext(activity.getparent()); alert.setview(input); alert.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { string value = input.gettext().tostring(); // onoffswitch.setchecked(false); // value! if(value.equals("1234")) { dialog.dismiss(); //onoffswitch.setchecked(false); iscorrectpin =true; } } }); alert.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { // canceled. } }); alert.show(); }
change displaypinalert this:
private void displaypinalert() { onoffswitch.setchecked(true); alertdialog.builder alert = new alertdialog.builder(activity.getparent()); alert.setmessage("enter pin"); // set edittext view user input final edittext input = new edittext(activity.getparent()); alert.setview(input); alert.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { string value = input.gettext().tostring(); // onoffswitch.setchecked(false); // value! if(value.equals("1234")) { dialog.dismiss(); onoffswitch.setchecked(false); } } }); alert.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { // canceled. } }); dialog = alert.show(); }
the problem caused fact dismiss old reference of dialog, not last created.
Comments
Post a Comment