Android ExpandableListView -
recently i'm trying use android's expandable list view, googled around , stumbled upon this
http://about-android.blogspot.com/2010/04/steps-to-implement-expandablelistview.html
i followed steps exactly, created file contain implementation of own adapter. on oncreate method of main activity call:
mentries = findviewbyid(r.id.entries); expandablelistadapter adapter = new myexpandablelistadapter(this); mentries.setadapter(adapter);
here's code (taken above url , modified):
import android.content.context; import android.view.gravity; import android.view.view; import android.view.viewgroup; import android.widget.abslistview; import android.widget.baseexpandablelistadapter; import android.widget.textview; public class myexpandablelistadapter extends baseexpandablelistadapter { private string[] groups = {"vehicle", "baj"}; private string[][] children = { {"mol", "mor"}, {"in", "ruh"} }; private context cxt; public myexpandablelistadapter(context cxt) { this.cxt = cxt; } @override public object getchild(int grouppos, int childpos) { return children[grouppos][childpos]; } @override public long getchildid(int grouppos, int childpos) { return childpos; } @override public view getchildview(int grouppos, int childpos, boolean islastchild, view convertview, viewgroup parent) { textview tv = getgenericview(); tv.settext(getchild(grouppos, childpos).tostring()); return tv; } @override public int getchildrencount(int grouppos) { return children[grouppos].length; } @override public object getgroup(int grouppos) { return groups[grouppos]; } @override public int getgroupcount() { return groups.length; } @override public long getgroupid(int grouppos) { return grouppos; } public textview getgenericview() { // layout parameters expandablelistview abslistview.layoutparams lp = new abslistview.layoutparams( viewgroup.layoutparams.fill_parent, 64); textview tv = new textview(this.cxt); tv.setlayoutparams(lp); // center text vertically tv.setgravity(gravity.center_vertical | gravity.left); // set text starting position tv.setpadding(36, 0, 0, 0); return tv; } @override public view getgroupview(int grouppos, boolean isexpanded, view convertview, viewgroup parent) { textview tv = getgenericview(); tv.settext(getgroup(grouppos).tostring()); return null; } @override public boolean hasstableids() { return true; } @override public boolean ischildselectable(int grouppos, int childpos) { return true; } }
the logcat spit these:
12-01 22:24:54.883: error/androidruntime(14424): java.lang.nullpointerexception 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.abslistview.obtainview(abslistview.java:1276) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.listview.makeandaddview(listview.java:1668) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.listview.filldown(listview.java:637) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.listview.fillfromtop(listview.java:694) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.listview.layoutchildren(listview.java:1521) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.abslistview.onlayout(abslistview.java:1113) 12-01 22:24:54.883: error/androidruntime(14424): @ android.view.view.layout(view.java:6830) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.relativelayout.onlayout(relativelayout.java:900) 12-01 22:24:54.883: error/androidruntime(14424): @ android.view.view.layout(view.java:6830) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.framelayout.onlayout(framelayout.java:333) 12-01 22:24:54.883: error/androidruntime(14424): @ android.view.view.layout(view.java:6830) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.linearlayout.setchildframe(linearlayout.java:1119) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.linearlayout.layoutvertical(linearlayout.java:998) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.linearlayout.onlayout(linearlayout.java:918) 12-01 22:24:54.883: error/androidruntime(14424): @ android.view.view.layout(view.java:6830) 12-01 22:24:54.883: error/androidruntime(14424): @ android.widget.framelayout.onlayout(framelayout.java:333) 12-01 22:24:54.883: error/androidruntime(14424): @ android.view.view.layout(view.java:6830) snip...
anyone care shed light on this? =/
edit: i've implemented methods required in base class.
edit2: code added
finally got it... it's at:
@override public view getgroupview(int grouppos, boolean isexpanded, view convertview, viewgroup parent) { textview tv = getgenericview(); tv.settext(getgroup(grouppos).tostring()); return null; }
it's returning null... shouldn't code when i'm sleepy =/
Comments
Post a Comment