android - How to make textview in expandable listview MATCH_PARENT -
i working on 3 level expandable list view. works expect width of textview of second , third level of expandable listview wrapping content , not matching parent i've specified in layout.
here code parent level adapter:
public class parentleveladapter extends baseexpandablelistadapter { private final context mcontext; private final list<string> mlistdataheader; private final map<string, list<string>> mlistdata_secondlevel_map; private final map<string, list<string>> mlistdata_thirdlevel_map; private list<string> stringlist = new arraylist<>(); activity activity; public parentleveladapter(context mcontext, list<string> mlistdataheader) { activity = (activity) mcontext; this.mcontext = mcontext; this.mlistdataheader = new arraylist<>(); this.mlistdataheader.addall(mlistdataheader); // second level string[] mitemheaders = new string[0]; mlistdata_secondlevel_map = new hashmap<>(); int parentcount = mlistdataheader.size(); mitemheaders = mcontext.getresources().getstringarray(r.array.items_array_expandable_level_two); mlistdata_secondlevel_map.put(mlistdataheader.get(i), arrays.aslist(mitemheaders)); } // third level string[] mitemchildofchild; mlistdata_thirdlevel_map = new hashmap<>(); (object o : mlistdata_secondlevel_map.entryset()) { map.entry entry = (map.entry) o; object object = entry.getvalue(); if (object instanceof list) { collections.addall(stringlist, (string[]) ((list) object).toarray()); mitemchildofchild = mcontext.getresources().getstringarray(r.array.items_array); } } } } @override public object getchild(int groupposition, int childposition) { return childposition; } @override public long getchildid(int groupposition, int childposition) { return childposition; } @override public view getchildview(int groupposition, int childposition,boolean islastchild, view convertview, viewgroup parent) { final customexpandablelistview secondlevelexplistview = new customexpandablelistview(this.mcontext); string parentnode = (string) getgroup(groupposition); secondlevelexplistview.setadapter(new secondleveladapter(this.mcontext, mlistdata_secondlevel_map.get(parentnode), mlistdata_thirdlevel_map)); secondlevelexplistview.setgroupindicator(null); secondlevelexplistview.setongroupexpandlistener(new expandablelistview.ongroupexpandlistener() { int previousgroup = -1; @override public void ongroupexpand(int groupposition) { if (groupposition != previousgroup) secondlevelexplistview.collapsegroup(previousgroup); previousgroup = groupposition; } }); secondlevelexplistview.setonchildclicklistener(new expandablelistview.onchildclicklistener() { @override public boolean onchildclick(expandablelistview parent, view v, int groupposition, int childposition, long id) { return false; } }); return secondlevelexplistview; } @override public int getchildrencount(int groupposition) { return 1; } @override public object getgroup(int groupposition) { return this.mlistdataheader.get(groupposition); } @override public int getgroupcount() { return this.mlistdataheader.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 layoutinflater = (layoutinflater) this.mcontext.getsystemservice(context.layout_inflater_service); convertview = layoutinflater.inflate(r.layout.expandable, parent, false); } textview lbllistheader = (textview) convertview.findviewbyid(r.id.lbllistheader); lbllistheader.settext(headertitle); return convertview; } @override public boolean hasstableids() { return true; } @override public boolean ischildselectable(int groupposition, int childposition) { return true; } }
second level adapter code:
public class secondleveladapter extends baseexpandablelistadapter { private final context mcontext; private final list<string> mlistdataheader; private final map<string, list<string>> mlistdatachild; public secondleveladapter(context mcontext, list<string> mlistdataheader, map<string, list<string>> mlistdatachild) { this.mcontext = mcontext; this.mlistdataheader = mlistdataheader; this.mlistdatachild = mlistdatachild; } @override public object getchild(int groupposition, int childposition) { return this.mlistdatachild.get(this.mlistdataheader.get(groupposition)).get(childposition); } @override public long getchildid(int groupposition, int childposition) { return childposition; } @override public view getchildview(int groupposition, int childposition, boolean islastchild, view convertview, viewgroup parent) { final string childtext = (string) getchild(groupposition, childposition); if (convertview == null) { layoutinflater layoutinflater = (layoutinflater) this.mcontext.getsystemservice(context.layout_inflater_service); convertview = layoutinflater.inflate(r.layout.expandable_third, parent, false); } textview txtlistchild = (textview) convertview.findviewbyid(r.id.lbllistthird); txtlistchild.settext(childtext); return convertview; } @override public int getchildrencount(int groupposition) { try { return this.mlistdatachild.get(this.mlistdataheader.get(groupposition)).size(); } catch (exception e) { return 0; } } @override public object getgroup(int groupposition) { return this.mlistdataheader.get(groupposition); } @override public int getgroupcount() { return this.mlistdataheader.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 layoutinflater = (layoutinflater) this.mcontext .getsystemservice(context.layout_inflater_service); convertview = layoutinflater.inflate(r.layout.expandable_list_second, parent, false); } textview lbllistheader = (textview) convertview .findviewbyid(r.id.lbllistitem); lbllistheader.settext(headertitle); return convertview; } @override public boolean hasstableids() { return true; } @override public boolean ischildselectable(int groupposition, int childposition) { return true; } }
and list row code contains 1 textbox is
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <textview android:id="@+id/lbllistthird" android:layout_width="match_parent" android:layout_height="@dimen/_35sdp" android:textcolor="@color/colorwhite" android:paddingleft="@dimen/_20sdp" android:layout_margintop="@dimen/_10sdp" android:textsize="25sp" android:layout_gravity="center" android:gravity="center|start" />
to more precise uploading picture give clear view of trying say. please have @ it. i've turned on "show layout bounds" developer option shows textview wrapping content of text , not matching parent. want textview clickable throughout , not till length of text.
please tell me doing wrong , needs done fix this.
for who's viewing or in future. solved removing code calculates width. don't know if right way go job done. here code snippet:
protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { heightmeasurespec = measurespec.makemeasurespec(999999, measurespec.at_most); super.onmeasure(widthmeasurespec, heightmeasurespec); }
Comments
Post a Comment