java - CheckBoxes are not getting cleared after clicking Next button -
i trying implement survey app in have ask few questions , question can have more 1 answer. have used checkbox problem facing when click on next button, next question appears on screen checkboxs checked last question still checked new question. want checkboxs cleared when click next button next question.
public class surveyactivity extends activity { button submit,conti,nextbtn; textview head,survey,optn1,optn2,optn3,optn4; string que,opt1,opt2,opt3,opt4; checkbox checkbox1,checkbox2,checkbox3,checkbox4; int surveyno=127; int questionno=1; public final static string tag_success = "success"; public static final string extra_message = "message"; string msg; private progressdialog pdialog; jsonparser jsonparser = new jsonparser(); protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_survey); submit=(button)findviewbyid(r.id.btnsumbit); conti=(button)findviewbyid(r.id.btncontinue); head=(textview)findviewbyid(r.id.tvproject); nextbtn=(button)findviewbyid(r.id.btnsubmtnxt); survey=(textview)findviewbyid(r.id.tvsurvey); optn1=(textview)findviewbyid(r.id.tvoptone); optn2=(textview)findviewbyid(r.id.tvopttwo); optn3=(textview)findviewbyid(r.id.tvoptthree); optn4=(textview)findviewbyid(r.id.tvoptfour); checkbox1=(checkbox)findviewbyid(r.id.chkopt1); checkbox2=(checkbox)findviewbyid(r.id.chkopt2); checkbox3=(checkbox)findviewbyid(r.id.chkopt3); checkbox4=(checkbox)findviewbyid(r.id.chkopt4); nextbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { { new fetchquestion().execute(); questionno++; }while(questionno>=22); } }); //font typeface type01=typeface.createfromasset(getassets(),"helveticaneue-ultralight.ttf"); head.settypeface(type01); submit.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent fours1 = new intent(surveyactivity.this, beginaction.class); startactivity(fours1); } }); conti.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent fours1 = new intent(surveyactivity.this, entrpnxtstart.class); startactivity(fours1); } }); new fetchquestion().execute(); } public void linkdn(view view) { intent intent=new intent(intent.action_view, uri.parse("https://www.linkedin.com")); startactivity(intent); } public void facebook(view view) { intent intent=new intent(intent.action_view, uri.parse("https://www.facebook.com")); startactivity(intent); } public void twiiter(view view) { intent intent=new intent(intent.action_view, uri.parse("https://twitter.com/")); startactivity(intent); } public void insta(view view) { intent intent=new intent(intent.action_view, uri.parse("https://www.instagram.com/")); startactivity(intent); } class fetchquestion extends asynctask<string, string, string> { private progressdialog progressdialog; @override protected void onpreexecute() { super.onpreexecute(); progressdialog = new progressdialog(surveyactivity.this); progressdialog.settitle("contacting servers"); progressdialog.setmessage("logging in ..."); progressdialog.setindeterminate(false); progressdialog.setcancelable(true); progressdialog.show(); } @override protected string doinbackground(string... args) { system.out.println("doinbackground entered!"); list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("questionno",string.valueof(questionno))); params.add(new basicnamevaluepair("surveyno",string.valueof(surveyno))); jsonobject json = jsonparser.makehttprequest("http://www.tikox.com/ws/survey.php","post", params); system.out.println("json object made, php should exec now!" + json.tostring()); log.d("create response", json.tostring()); try { int success = json.getint(tag_success); if (success == 1) { system.out.println(" details fetched successfully!"); string msg = json.getstring("message"); system.out.println(" msg " + msg); que = json.getstring("question"); system.out.println(" que " + que); opt1 = json.getstring("option1"); system.out.println(" opt1 " + opt1); opt2 = json.getstring("option2"); system.out.println(" opt2 " + opt2); opt3 = json.getstring("option3"); system.out.println(" opt3 " + opt3); opt4 = json.getstring("option4"); system.out.println(" opt4 " + opt4); } else { system.out.print("unsuccessfull "); msg = json.getstring("message"); system.out.print(msg); runonuithread(new runnable() { @override public void run() { toast.maketext(getapplicationcontext(), msg, toast.length_long).show(); } }); } } catch (jsonexception e) { e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { progressdialog.dismiss(); survey.settext(que); optn1.settext(opt1); optn2.settext(opt2); optn3.settext(opt3); optn4.settext(opt4); } } }
you need clear check boxes once next clicked. add below code onpostexecute().
checkbox1.setchecked(false); checkbox2.setchecked(false); checkbox3.setchecked(false); checkbox4.setchecked(false);
Comments
Post a Comment