adapter - android getChildView is not being called after notifyDataSetChanged -
i have expandablelistview , tried change childs that:
((subitem) adapter.getchild(i+1, 5)).setcount(unreadbox); adapter.notifydatasetchanged();
here adapter class:
public class draweradapter extends baseexpandablelistadapter { private context context; private list<item> items; private list<list<subitem>> subitems; public draweradapter(context context, list<item> items, list<list<subitem>> subitems) { this.context = context; this.items = items; this.subitems = subitems; } @override public int getgroupcount() { return items.size(); } @override public int getchildrencount(int groupposition) { return subitems.get(groupposition).size(); } @override public object getgroup(int position) { return items.get(position); } @override public object getchild(int groupposition, int childposition) { return subitems.get(groupposition).get(childposition); } @override public long getgroupid(int position) { return position; } @override public long getchildid(int groupposition, int childposition) { return childposition; } @override public boolean hasstableids() { return false; } @override public view getgroupview(int groupposition, boolean isexpanded, view view, viewgroup viewgroup) { item item = (item) getgroup(groupposition); if (view == null) { layoutinflater layoutinflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view = layoutinflater.inflate(r.layout.list_drawer_group, null); } imageview iconview = (imageview) view.findviewbyid(r.id.icon_view); if (item.icondrawableid != null) { iconview.setimageresource(item.icondrawableid); iconview.setvisibility(view.visible); } else { iconview.setvisibility(view.gone); } textview groupheader = (textview) view.findviewbyid(r.id.group_header); groupheader.settext(item.title); if (item.icondrawableid != null) { groupheader.setpadding( dimensionhelper.dptopixels(context, 4.0f), 0, dimensionhelper.dptopixels(context, 16.0f), 0); } else { groupheader.setpadding( dimensionhelper.dptopixels(context, 16.0f), 0, dimensionhelper.dptopixels(context, 16.0f), 0); } imageview imageview = (imageview) view.findviewbyid(r.id.image_view); imageview.setimageresource(isexpanded ? r.drawable.ic_navigation_collapse : r.drawable.ic_navigation_expand); imageview.setvisibility(getchildrencount(groupposition) > 0 ? view.visible : view.gone); return view; } @override public view getchildview(int groupposition, int childposition, boolean isexpanded, view view, viewgroup viewgroup) { subitem subitem = (subitem) getchild(groupposition, childposition); if (view == null) { layoutinflater layoutinflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view = layoutinflater.inflate(r.layout.list_drawer_item, null); } textview colorpreview = (textview) view.findviewbyid(r.id.colorpreview); if (subitem.getcolor() != -1) { colorpreview.setbackgroundcolor(subitem.getcolor()); colorpreview.setvisibility(view.visible); } else { colorpreview.setvisibility(view.gone); } imageview iconview = (imageview) view.findviewbyid(r.id.icon_view); if (subitem.icondrawableid != null) { iconview.setimageresource(subitem.icondrawableid); iconview.setvisibility(view.visible); } else { iconview.setvisibility(view.gone); } textview title = (textview) view.findviewbyid(r.id.title_text_view); title.settext(subitem.title); if (subitem.icondrawableid != null) { title.setpadding( dimensionhelper.dptopixels(context, 4.0f), 0, dimensionhelper.dptopixels(context, 16.0f), 0); } else { title.setpadding( dimensionhelper.dptopixels(context, 40.0f), 0, dimensionhelper.dptopixels(context, 16.0f), 0); } textview counter = (textview) view.findviewbyid(r.id.counter_text_view); counter.settext(string.valueof(subitem.count)); counter.setvisibility(subitem.count > 0 ? view.visible : view.gone); return view; } @override public boolean ischildselectable(int groupposition, int childposition) { return true; } public static class item { protected string title; protected integer icondrawableid; protected listener listener; public item(string title, integer icondrawableid, listener listener) { this.title = title; this.icondrawableid = icondrawableid; this.listener = listener; } public listener getlistener() { return listener; } public static interface listener { public void onclick(fragmentmanager fragmentmanager); } } public static class subitem extends item { protected long count; protected int color; public subitem(string title, integer icondrawableid, long count, int color, listener listener) { super(title, icondrawableid, listener); this.count = count; this.color = color; } public long getcount() { return count; } public void setcount(long count) { this.count = count; } public int getcolor() { return color; } public void setcolor(int color) { this.color = color; } } }
notifydatasetchanged() method not working properly, getchildview being called not,please in order fix issue.
you changing value child item not setting inside of adapter.
subitem item = ((subitem) adapter.getchild(i+1, 5)).setcount(unreadbox); adapter.setchild(i+1,5,item); adapter.notifydatasetchanged();
add in adapter
@override public void setchild(int groupposition, int childposition,subitem item) { subitems.get(groupposition).get(childposition) = item; }
Comments
Post a Comment