ListView with Checkboxes Android -


the activity below, contactmailadapter.class list view adapter containing checkbox. if want position of row has been checked. how can done. have several checkboxes in list , can checked multiple checkbox. logic should store each position has been checked. call data arraylist not able position of checked item adapter.

public class contactmailadapter extends baseadapter {      private activity activity;     private arraylist<destinataire> data;     private static layoutinflater inflater = null;      viewholder holder;     static string src;      popmessage main;      public contactmailadapter(activity a, arraylist<destinataire> marticles) {          activity = a;         data = marticles;         inflater = (layoutinflater) activity.getsystemservice(context.layout_inflater_service);      }        public contactmailadapter (popmessage m){                 this.main=m;     }       @override     public int getcount() {         return data.toarray().length;      }      @override     public object getitem(int position) {          return position;     }      @override     public long getitemid(int position) {         return position;     }      public static class viewholder {          public textview one;         public textview two;         public checkbox check;      }      @override     public view getview(final int position, view convertview, viewgroup parent) {         view vi = convertview;          if (convertview == null) {              vi = inflater.inflate(r.layout.popise_item, null);             holder = new viewholder();             holder.one = (textview) vi.findviewbyid(r.id.title_top);             holder.two = (textview) vi.findviewbyid(r.id.title_bottom);             holder.check = (checkbox)vi.findviewbyid(r.id.search_imag);             vi.settag(holder);          } else             holder = (viewholder) vi.gettag();               holder.one.settext(data.get(position).getname());             holder.two.settext(data.get(position).getemail());                 vi.findviewbyid(r.id.search_imag).setonclicklistener(new onclicklistener(){                  @override                 public void onclick(view v) {                     // todo auto-generated method stub                      if (holder.check.ischecked())                         system.out.println("false"+v.getid());                     else                          system.out.println("false");                  }             });               holder.check.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener()                                        {                       @override                       public void oncheckedchanged(compoundbutton buttonview,                               boolean ischecked) {                          }                   });            /*  vi.findviewbyid(r.id.search_image).setonclicklistener(new onclicklistener(){                 @override                 public void onclick(view v) {                     // todo auto-generated method stub                     v.findviewbyid(r.id.search_image).setbackgroundresource(r.drawable.boutton_off);                     if (holder.check.ischecked())                         system.out.println("true");                     else                          system.out.println("false");                  }             }); */            return vi;     }   } 

new update

ids = new arraylist<string>();             if (ids.contains(holder.check.getid() + "")) {                         holder.check.setchecked(true);                     } else {                         holder.check.setchecked(false);                     }                      holder.check                             .setoncheckedchangelistener(new oncheckedchangelistener() {                                    public void oncheckedchanged(compoundbutton buttonview,                                         boolean ischecked) {                                     // todo auto-generated method stub                                     int id = buttonview.getid();                                      if (ischecked) {                                         if (ids.contains(id + "")) {                                         } else {                                             ids.add(id + "");                                             id++;                                             system.out.println( "receipe" + id);                                          }                                     } else {                                         if (ids.contains(id + "")) {                                             ids.remove(id + "");                                             system.out.println( "receipe" + id);                                            //  ids--;                                         } else { //                                        id = 0;                                         }                                      }                                  }                             }); 

have @ sample provide perfect solution have used selected position in project. worked charm concept of

checkbox.settag , gettag() methods. hope .  

http://amitandroid.blogspot.in/2013/03/android-listview-with-checkbox-and.html


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -