edit:do not put listview in expandableview. first problem.second 1 graph's height zero.(look in details http://developer.android.com/guide/topics/ui/how-android-draws.html ) these problems.for listview used textviews , put values in them loop. graph problem check device's pixel values , setlayoutparameters depending on whether portrait or landscape.here code used it.it gives values on devices use there may better solution.
int orientation = getresources().getconfiguration().orientation; displaymetrics metrics = new displaymetrics(); getactivity().getwindowmanager().getdefaultdisplay().getmetrics(metrics); int height=metrics.heightpixels; int width = metrics.widthpixels; if (orientation == 1) { sgv.setlayoutparams(new layoutparams(width, height/4)); } else { sgv.setlayoutparams(new layoutparams(width, height/2)); }
i'm implementing expandablelistview has 2 different type of children view , listview.i use 2 different layout files both have 2 child layout child_list.xml , child_img.xml
the problem if don't set layout width , height gives normal width 0 height view , normal width , not enough height listview can see 1 element of listview.however if set layoutparameters (1200,400) show listview elements.
without setting height or width how can show list elements?
main layout
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/distance_fragment_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <expandablelistview android:id="@+id/expandablelist" android:layout_width="fill_parent" android:layout_height="fill_parent" android:groupindicator="@null" > </expandablelistview> </linearlayout>
group.xml
<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/groupname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="textview" android:textsize="50sp" /> </linearlayout>
children_list.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <listview android:id="@+id/child_listview" android:layout_width="wrap_content" android:layout_height="wrap_content" > </listview> </linearlayout>
children_list_txt
<linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <textview android:id="@+id/distance_list_home" android:layout_width="200dp" android:layout_height="50dp" android:gravity="right|center_vertical" android:textcolor="#ffffff" android:textsize="18sp" /> <textview android:id="@+id/distance_list_away" android:layout_width="200dp" android:layout_height="50dp" android:gravity="left|center_vertical" android:textcolor="#ffffff" android:textsize="18sp" /> </linearlayout> </linearlayout>
myexpandablelistviewadapter
public class expandablelistitems extends baseexpandablelistadapter { private context context; private arraylist<string> mparent; public expandablelistitems(context context, arraylist<string> parent) { mparent = parent; this.context = context; } @override public int getgroupcount() { return mparent.size(); } @override public int getchildrencount(int i) { return 1; } @override public string getgroup(int i) { return mparent.get(i); } @override public object getchild(int i, int i1) { return mparent.get(i); } @override public long getgroupid(int i) { return i; } @override public long getchildid(int i, int i1) { return i1; } @override public boolean hasstableids() { return true; } @override public boolean ischildselectable(int i, int i1) { return true; } @override public void registerdatasetobserver(datasetobserver observer) { super.registerdatasetobserver(observer); } @override public view getchildview(int groupposition, int childposition, boolean islastchild, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); if(groupposition == 1){ convertview = inflater.inflate(r.layout.distance_child_img, null); viewgroup grapharea = (viewgroup)convertview.findviewbyid(r.id.testw); speedgraphview sgv = new speedgraphview(getactivity().getbasecontext()); sgv.setarrays(homefirsthalfspeedarray,homesecondhalfspeedarray,global.app.match.hometeam.getteamname()); sgv.setplayerarrays(awayfirsthalfspeedarray,awaysecondhalfspeedarray,global.app.match.awayteam.getteamname()); sgv.setlayoutparams(new layoutparams(1200, 400)); grapharea.addview(sgv); }else{ convertview = layoutinflater.from(getactivity()).inflate(r.layout.distance_child_list, null); listview listv = (listview) convertview.findviewbyid(r.id.child_listview); listadapter adp = new listadapter(getactivity()); adp.add(new listitem("deneme", "away", 200, 100)); adp.add(new listitem("asdas", "away", 200, 100)); listv.setadapter(adp); // listv.setlayoutparams(new linearlayout.layoutparams(1200,500)); } return convertview; } @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); convertview = inflater.inflate(r.layout.distance_group, null); textview tx = (textview)convertview.findviewbyid(r.id.groupname); tx.settext(explistitems.get(groupposition)); return convertview; } }
Comments
Post a Comment