android - Custom ViewGroup, GridView, and SimpleCursorAdapter -
i need display data in 3 textviews, inside each grid item, want each grid item square. cursoradapter based on search.
based on necessities found research should creating own viewgroup each grid item , setting height same width (in onmeasurement), produces proper squares. data cursoradapter not show in views.
i can tell cursoradapter being referenced because number of white boxes in gridview changes depending on search.
where going wrong?
<ubiquia.sqbxsync.main.gridviewgroup xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ffffff"> <relativelayout android:id="@+id/gridlayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff"> <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:ellipsize="end" android:singleline="true" android:text="textview" android:textsize="15dp" android:textcolor="#ff000000" /> <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/textview1" android:layout_marginleft="10dp" android:ellipsize="end" android:singleline="true" android:text="textview" android:textsize="11dp" android:textcolor="#ff000000" /> <textview android:id="@+id/textview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textview2" android:layout_marginleft="10dp" android:ellipsize="end" android:singleline="true" android:text="textview" android:textsize="11dp" android:textcolor="#ff000000" /> </relativelayout>
package ubiquia.sqbxsync.main; import android.content.context; import android.util.attributeset; import android.view.viewgroup; public class gridviewgroup extends viewgroup { public gridviewgroup(context context, attributeset attrs) { super(context, attrs); } @override protected void onlayout(boolean changed, int l, int t, int r, int b) { // nothing } @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { super.onmeasure(widthmeasurespec, widthmeasurespec); } }
my cursoradapter
public class gridcursoradapter extends cursoradapter { public gridcursoradapter(context context, cursor c) { super(context, c); } @override public view newview(context context, cursor cursor, viewgroup parent) { layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); view gridview = inflater.inflate(r.layout.grid_item, null, true); return gridview; } @override public void bindview(view view, context context, cursor cursor) { textview tv1 = (textview) view.findviewbyid(r.id.textview1); textview tv2 = (textview) view.findviewbyid(r.id.textview2); textview tv3 = (textview) view.findviewbyid(r.id.textview3); tv1.settext(cursor.getstring(cursor.getcolumnindexorthrow("trackingnumber"))); tv2.settext(cursor.getstring(cursor.getcolumnindexorthrow("recipient_name"))); tv3.settext(cursor.getstring(cursor.getcolumnindexorthrow("carrier_name"))); } }
i found out after changing extends linearlayout , writing in super.onlayout(changed,l,t,r,b); shows layout in square wanted.
Comments
Post a Comment