android - Child View items are not refreshing -


here's code expandable listview in each grouo has checkbox , textview. there's select checkbox, on click should change states of child view's checkboxes not happening. can explain why??

mainactivity.java

public class mainactivity extends actionbaractivity implements onclicklistener {       expandablelistadapter listadapter;         expandablelistview explistview;         list<string> listdataheader;         static checkbox selectall;         hashmap<string, list<string>> listdatachild;          @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_main);              // listview             explistview = (expandablelistview) findviewbyid(r.id.expandablelistview1);             selectall=(checkbox)findviewbyid(r.id.checkbox1);             // preparing list data             preparelistdata();              listadapter = new expandablelistadapter(this, listdataheader, listdatachild);              // setting list adapter             explistview.setadapter(listadapter);             selectall.setonclicklistener(this);          }          /*          * preparing list data          */         private void preparelistdata() {             listdataheader = new arraylist<string>();             listdatachild = new hashmap<string, list<string>>();              // adding child data             listdataheader.add("top 250");             listdataheader.add("now showing");             listdataheader.add("coming soon..");              // adding child data             list<string> top250 = new arraylist<string>();             top250.add("the shawshank redemption");             top250.add("the godfather");              list<string> nowshowing = new arraylist<string>();             nowshowing.add("the conjuring");             nowshowing.add("despicable me 2");               list<string> comingsoon = new arraylist<string>();             comingsoon.add("2 guns");             comingsoon.add("the smurfs 2");               listdatachild.put(listdataheader.get(0), top250); // header, child data             listdatachild.put(listdataheader.get(1), nowshowing);             listdatachild.put(listdataheader.get(2), comingsoon);         }          @override         public void onclick(view arg0) {             // todo auto-generated method stub             checkbox cb=(checkbox)listadapter.getchildview(0, 0, false, null,         null).findviewbyid(r.id.cb_child);             cb.setchecked(true);             ((baseexpandablelistadapter) listadapter).notifydatasetchanged();         }  } 

expandablelistadapter.java

public class expandablelistadapter extends baseexpandablelistadapter  {      private context _context;     private list<string> _listdataheader; // header titles     private hashmap<string, list<string>> _listdatachild;       public expandablelistadapter(context context, list<string> listdataheader,             hashmap<string, list<string>> listchilddata) {         this._context = context;         this._listdataheader = listdataheader;         this._listdatachild = listchilddata;      }      @override     public object getchild(int groupposition, int childposititon) {         return this._listdatachild.get(this._listdataheader.get(groupposition))                 .get(childposititon);     }      @override     public long getchildid(int groupposition, int childposition) {         return childposition;     }      @override     public view getchildview(final int groupposition, final int childposition,             boolean islastchild, view convertview, viewgroup parent) {          final string childtext = (string) getchild(groupposition, childposition);          if (convertview == null) {             layoutinflater infalinflater = (layoutinflater) this._context                     .getsystemservice(context.layout_inflater_service);             convertview = infalinflater.inflate(r.layout.child_layout, null);         }          return convertview;     }      @override     public int getchildrencount(int groupposition) {         return this._listdatachild.get(this._listdataheader.get(groupposition))                 .size();     }      @override     public object getgroup(int groupposition) {         return this._listdataheader.get(groupposition);     }      @override     public int getgroupcount() {         return this._listdataheader.size();     }      @override     public long getgroupid(int groupposition) {         return groupposition;     }      @override     public view getgroupview(int groupposition, boolean isexpanded,             view convertview, viewgroup parent) {         string headertitle = (string) getgroup(groupposition);         if (convertview == null) {             layoutinflater infalinflater = (layoutinflater) this._context                     .getsystemservice(context.layout_inflater_service);             convertview = infalinflater.inflate(r.layout.group_layout, null);         }          textview lbllistheader = (textview) convertview                 .findviewbyid(r.id.textview1);         lbllistheader.settypeface(null, typeface.bold);         lbllistheader.settext(headertitle);          return convertview;     }     } 

activity_main.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/container"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.example.expandablelisttest.mainactivity"     tools:ignore="mergerootframe" >      <expandablelistview         android:layout_margintop="100dp"         android:id="@+id/expandablelistview1"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_alignparentleft="true" >      </expandablelistview>      <checkbox         android:id="@+id/checkbox1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_margintop="21dp"         android:text="select all" />  </relativelayout> 

child_layout.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <checkbox         android:id="@+id/cb_child"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_margintop="18dp"         android:text="checkbox"          android:checked="false"/>  </relativelayout> 

group_layout.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="18dp"         android:layout_margintop="14dp"         android:text="textview" />  </relativelayout> 

method getchildview(..) used adapter populate expandable child view under group.

i can encourage create own expandablelistadapter extends baseexpandablelistadapter (if have 1 group = 1 item, can use 1 arraylist own pojo object model)

and finnaly, full explanation, when call notifydatasetchanged(), list refresh view adapter's data (example each boolean , use there value check or uncheck checkbox)


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -