how status of checkbox in textview while using alertdialog.
still trying show checked status of checkbox not getting value neither true nor false.
please see below screenshot,
uploadactivity.java code:
textview tv1; checkbox chkios; @override public dialog oncreatedialog(int id) { alertdialog dialogdetails = null; switch (id) { case dialog_login: layoutinflater inflater = layoutinflater.from(this); view dialogview = inflater.inflate(r.layout.dialog_layout, null); alertdialog.builder dialogbuilder = new alertdialog.builder(this); dialogbuilder.settitle("image information"); dialogbuilder.setview(dialogview); dialogdetails = dialogbuilder.create(); break; } return dialogdetails; } @override public void onpreparedialog(int id, dialog dialog) { switch (id) { case dialog_login: final alertdialog alertdialog = (alertdialog) dialog; button loginbutton = (button) alertdialog .findviewbyid(r.id.btn_login); button cancelbutton = (button) alertdialog .findviewbyid(r.id.btn_cancel); tv1 = (textview) alertdialog .findviewbyid(r.id.textview1); chkios = (checkbox) alertdialog .findviewbyid(r.id.chkoption1); loginbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { savedata(); addlisteneronbutton(); } private boolean savedata() { ............. } return true; } private string gethttppost(string url, list<namevaluepair> params) { ............. } return str.tostring(); } }); cancelbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { ........... } }); } } public void addlisteneronbutton() { chkios.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if (((checkbox) v).ischecked()) tv1.settext("true"); else tv1.settext("false"); } }); }
chekbox.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { // todo auto-generated method stub if(ischecked==true){ status.settext("true"); } }else if(ischecked==false){ status.settext("false"); } } });
edit below line
chkios = (checkbox) alertdialog.findviewbyid(r.id.chkoption1);
use code remove
addlisteneronbutton()
this function it'll work sure. thanks.
Comments
Post a Comment