android - Custom Expandablelistview unsorting data -
i have expandable listview data, stored in list , in hashmap. problem expandable listview showing data unsorted when collapse , expand group. i'm going crazy!!!
import java.util.arrays; import java.util.hashmap; import java.util.hashset; import java.util.list; import java.util.set; import android.content.context; import android.graphics.color; import android.graphics.typeface; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseexpandablelistadapter; import android.widget.filter; import android.widget.linearlayout; import android.widget.textview; import com.pebbo.yaa.r; public class customexpandablelistadapter extends baseexpandablelistadapter { private context _context; private list<pojoalgcat> _listdataheader; // header titles // child data in format of header title, child title private hashmap<pojoalgcat, list<pojoalg>> _listdatachild; integer[] algs_lite = {5, 19}; integer[] algs_cat_lite = {1, 2}; linearlayout ll_row, ll_row_child; textview lbllistheader; textview txtlistchild; public customexpandablelistadapter(context context, list<pojoalgcat> listdataheader, hashmap<pojoalgcat, list<pojoalg>> 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); } public object getchildtitle(int groupposition, int childposititon) { return this._listdatachild.get(this._listdataheader.get(groupposition)).get(childposititon).getname(); } @override public long getchildid(int groupposition, int childposition) { return this._listdatachild.get(this._listdataheader.get(groupposition)).get(childposition).getid(); } public int getcatid(int groupposition) { return this._listdataheader.get(groupposition).getid(); } public int getalgid(int groupposition, int childposition) { return this._listdatachild.get(this._listdataheader.get(groupposition)).get(childposition).getid(); } @override public view getchildview(int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { final string childtext = (string) getchildtitle(groupposition, childposition); boolean exists = containsvalue(algs_lite, getalgid(groupposition, childposition)); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context.getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_item, null); ll_row_child = (linearlayout) convertview.findviewbyid(r.id.ll_row_child); txtlistchild = (textview) convertview.findviewbyid(r.id.lbllistitem); if(exists){ //log.i("adapter1", "value:::" + exists + ":::id:::" + f.getid() + ":::name:::" + f.getname() + ":::disponible"); ll_row_child.setbackgroundcolor(color.white); txtlistchild.settextcolor(_context.getresources().getcolor(r.color.darkbluebg)); }else{ //log.e("adapter1", "value:::" + exists + ":::id:::" + f.getid() + ":::name:::" + f.getname() + ":::no disponible"); ll_row_child.setbackgroundcolor(color.ltgray); txtlistchild.settextcolor(color.gray); } } txtlistchild.settext(childtext); 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); } public object getgrouptitle(int groupposition) { return this._listdataheader.get(groupposition).getcategory(); } @override public int getgroupcount() { return this._listdataheader.size(); } @override public long getgroupid(int groupposition) { return this._listdataheader.get(groupposition).getid(); } @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) { string headertitle = (string) getgrouptitle(groupposition); boolean exists_alg = containsvalue(algs_cat_lite, getcatid(groupposition)); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_group, null); ll_row = (linearlayout) convertview.findviewbyid(r.id.ll_row); lbllistheader = (textview) convertview.findviewbyid(r.id.lbllistheader); if(exists_alg){ //log.i("adapter1", "value:::" + exists + ":::id:::" + f.getid() + ":::name:::" + f.getname() + ":::disponible"); ll_row.setbackgroundcolor(_context.getresources().getcolor(r.color.bluebg)); lbllistheader.settextcolor(color.white); }else{ //log.e("adapter1", "value:::" + exists + ":::id:::" + f.getid() + ":::name:::" + f.getname() + ":::no disponible"); ll_row.setbackgroundcolor(_context.getresources().getcolor(r.color.dimgray)); lbllistheader.settextcolor(_context.getresources().getcolor(r.color.lightgrey)); } } lbllistheader.settext(headertitle); return convertview; } @override public boolean hasstableids() { return false; } @override public boolean ischildselectable(int groupposition, int childposition) { return true; } public static boolean containsvalue(integer[] arr, integer targetvalue) { set<integer> set = new hashset<integer>(arrays.aslist(arr)); return set.contains(targetvalue); } }
what i'm doing wrong?? :(
Comments
Post a Comment