android - Tick or untick checkboxes when clicking on the list item -


so @ moment have got listview, checkboxes @ end of each row. right now, when tick box box gets ticked , unticked. want when click on listview item/row checkbox gets ticked or unticked.

here's code:

public class myactivity3 extends activity { private textview tv; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_my3);     button m = (button) findviewbyid(r.id.button3);     tv = (textview) findviewbyid(r.id.textviewcat);     typeface typeface = typeface.createfromasset(getassets(), "bebasneue bold.ttf");     tv.settypeface(typeface);       string listarray[] = new string[] { "all", "friends & family", "sports", "outside",             "at school", "fitness", "photography", "food", "beach", "money" };     listview listview = (listview) findviewbyid(r.id.listview);     list<hashmap<string, string>> alist = new arraylist<hashmap<string, string>>();     (int = 0; <= listarray.length - 1; i++) {        hashmap<string, string> hm = new hashmap<string, string>();         hm.put("title", listarray[i]);         alist.add(hm);     }     string[] sfrm = { "title"};     int[] sto = { r.id.title};     simpleadapter adapter = new simpleadapter(getbasecontext(), alist,             r.layout.row_layout, sfrm, sto);    listview.setadapter(adapter);    listview.setonitemclicklistener(new adapterview.onitemclicklistener() {          @override         public void onitemclick(adapterview<?> arg0, view view,                                 int position, long id) {             switch (position) {              }          }     }); } 

    @override     public void onitemclick(adapterview<?> arg0, view view,position, long id) {     checkbox cb = (checkbox) view.findviewbyid(r.id.your_checkbox);         cb.setchecked(!cb.ischecked());     } 

this makes item checked if wasnt, , unchecks if was.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -