android - Perform an action when a number of checkboxes are checked -
my app have 10 checkboxes, when 5 checkboxes checked want display picture in imageview below. dont know how code it. if here can me code greatful.
public class babyconquistas extends appcompatactivity { edittext conqtext1, conqtext2, button button; imageview img, img1; checkbox conq1, conq2, conq3, conq4, conq5, conq6, conq7, conq8, conq9, conq10; int cbcounter1=0, cbcounter2=0; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_babyconquistas); img = (imageview) findviewbyid(r.id.imgconq2); img1 = (imageview) findviewbyid(r.id.imgconq4); conq1 = (checkbox) findviewbyid(r.id.conq1); conq2 = (checkbox) findviewbyid(r.id.conq2); conq3 = (checkbox) findviewbyid(r.id.conq3); conq4 = (checkbox) findviewbyid(r.id.conq4); conq5 = (checkbox) findviewbyid(r.id.conq5); conq6 = (checkbox) findviewbyid(r.id.conq6); conq7 = (checkbox) findviewbyid(r.id.conq7); conq8 = (checkbox) findviewbyid(r.id.conq8); conq9 = (checkbox) findviewbyid(r.id.conq9); conq10 = (checkbox) findviewbyid(r.id.conq10); conqtext1 = (edittext) findviewbyid(r.id.conq1text); conqtext2 = (edittext) findviewbyid(r.id.conq2text); button = (button) findviewbyid(r.id.salvar); conq1.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter1 = cbcounter1 + 1; } else { cbcounter1 = cbcounter1 - 1; } if(cbcounter1 == 5) { img.setimageresource(r.drawable.img); //or if want handle visibility img.setvisibility(view.visible); } } }); conq2.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter1 = cbcounter1 + 1; } else { cbcounter1 = cbcounter1 - 1; } if(cbcounter1 == 5) { img.setimageresource(r.drawable.img); //or if want handle visibility img.setvisibility(view.visible); } } }); conq3.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter1 = cbcounter1 + 1; } else { cbcounter1 = cbcounter1 - 1; } if(cbcounter1 == 5) { img.setimageresource(r.drawable.img); //or if want handle visibility img.setvisibility(view.visible); } } }); conq4.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter1 = cbcounter1 + 1; } else { cbcounter1 = cbcounter1 - 1; } if(cbcounter1 == 5) { img.setimageresource(r.drawable.img); //or if want handle visibility img.setvisibility(view.visible); } } }); conq5.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter1 = cbcounter1 + 1; } else { cbcounter1 = cbcounter1 - 1; } if(cbcounter1 == 5) { img.setimageresource(r.drawable.img); //or if want handle visibility img.setvisibility(view.visible); } } }); conq6.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter2 = cbcounter2 + 1; } else { cbcounter2 = cbcounter2 - 1; } if(cbcounter2 == 5) { img1.setimageresource(r.drawable.img); //or if want handle visibility img1.setvisibility(view.visible); } } }); conq7.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter2 = cbcounter2 + 1; } else { cbcounter2 = cbcounter2 - 1; } if(cbcounter2 == 5) { img1.setimageresource(r.drawable.img); //or if want handle visibility img1.setvisibility(view.visible); } } }); conq8.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter2 = cbcounter2 + 1; } else { cbcounter2 = cbcounter2 - 1; } if(cbcounter2 == 5) { img1.setimageresource(r.drawable.img); //or if want handle visibility img1.setvisibility(view.visible); } } }); conq9.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter2 = cbcounter2 + 1; } else { cbcounter2 = cbcounter2 - 1; } if(cbcounter2 == 5) { img1.setimageresource(r.drawable.img); //or if want handle visibility img1.setvisibility(view.visible); } } }); conq10.setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if(ischecked){ cbcounter2 = cbcounter2 + 1; } else { cbcounter2 = cbcounter2 - 1; } if(cbcounter2 == 5) { img1.setimageresource(r.drawable.img); //or if want handle visibility img1.setvisibility(view.visible); } } }); }
this code task. , if need store information in sharedpref, can store counter value , checked, checkboxes info, on page load need populate data of checked checkboxes , counter
Comments
Post a Comment