android - recycling view including RadioButtons in a multiple layout ListView -


i tried lot of different posts here nothing gave me solution. doesn't matter style tried: without viewholder, viewholder, 2 viewholders... every time clicked radiobutton , scroll, views repeated.

checklist.xml

         <listview          android:id="@+id/lv_cl"          android:choicemode="singlechoice"          android:layout_below="@id/iv_cl_bar"          android:layout_height="match_parent"          android:layout_width="match_parent"          android:layout_marginbottom="25dp"          /> 

listitem_header.xml

<linearlayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">  <textview     android:id="@+id/tv_item_nr"     style="@style/tv_cl"     android:layout_marginleft="@dimen/customlist_marginleft"     android:layout_width="@dimen/checklist_nr_width"     android:text="1"      />  <textview     android:id="@+id/tv_item_issue"     style="@style/tv_cl"     android:layout_width="@dimen/checklist_issue_width"     android:layout_torightof="@id/tv_item_nr"     android:layout_marginleft="@dimen/checklist_tv_bar_marginleft"     /> </linearlayout> 

listitem.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" >  <textview     android:id="@+id/tv_item_nr"     style="@style/tv_cl"     android:layout_marginleft="@dimen/customlist_marginleft"     android:layout_width="@dimen/checklist_nr_width" />   <textview     android:id="@+id/tv_item_issue"     style="@style/tv_cl"     android:layout_width="@dimen/checklist_issue_width"     android:layout_marginleft="@dimen/checklist_tv_bar_marginleft"     android:layout_torightof="@id/tv_item_nr" />  <radiogroup     android:id="@+id/rg"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_marginleft="@dimen/checklist_tv_bar_marginleft"     android:layout_torightof="@id/tv_item_issue"     android:orientation="horizontal" >      <!--android:background="@drawable/checkbox_none"     android:button="@null"     -->     <radiobutton         android:id="@+id/rb_ok"         android:layout_width="wrap_content"         android:layout_height="wrap_content"      />      <radiobutton         android:id="@+id/rb_open"         android:layout_width="wrap_content"         android:layout_height="wrap_content"           /> </radiogroup> </linearlayout> 

customadapter

    static class viewholder {     textview tv_nr;     textview tv_issue;     radiobutton rb_ok, rb_open; }  public class listviewcustomadapter extends baseadapter {      arraylist<item> checklistitems;     public layoutinflater inflater;     public activity context;      public listviewcustomadapter(activity context, arraylist<item> itemlist) {         super();         this.context = context;         this.checklistitems = itemlist;      }      private static final int question = 0;     private static final int header = 1;     private static final int type_max_count = 2;      @override     public int getitemviewtype(int position) {         item item = (item) getitem(position);         if (item.isquestion()) {             return question;         } else {             return header;         }     }      @itemclick     void lv_cl(item item) {      }      @override     public int getviewtypecount() {         return type_max_count;     }      @override     public int getcount() {         return checklistitems.size();     }      @override     public object getitem(int position) {         return checklistitems.get(position);     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(final int position, view convertview, viewgroup parent) {          viewholder viewholder;          int type = getitemviewtype(position);         final item item = (item) getitem(position);          if (convertview == null) {              this.inflater = (layoutinflater) context                     .getsystemservice(context.layout_inflater_service);             viewholder = new viewholder();              switch (type) {                 case header:                     convertview = inflater.inflate(                             r.layout.checklist_listitem_header, null);                     break;                  case question:                     convertview = inflater.inflate(r.layout.checklist_listitem,                             null);                     viewholder.rb_ok = (radiobutton) convertview                             .findviewbyid(r.id.rb_ok);                     viewholder.rb_ok.setonclicklistener(new view.onclicklistener() {                         @override                         public void onclick(view view) {                             item.setselectyes(true);                         }                     });                     viewholder.rb_open = (radiobutton) convertview                             .findviewbyid(r.id.rb_open);                      convertview.settag (viewholder);                      break;             }             viewholder.tv_nr = (textview) convertview                     .findviewbyid(r.id.tv_item_nr);             viewholder.tv_issue = (textview) convertview                     .findviewbyid(r.id.tv_item_issue);             convertview.settag (viewholder);         }          else         {             viewholder = (viewholder) convertview.gettag();         }          viewholder.tv_nr.settext(item.getgeneratednumber());         viewholder.tv_issue.settext(item.getquestion());          switch (type){             case question:                 viewholder.rb_ok.setselected(item.isselectyes());                 break;         }         return convertview;     } } 


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -