问题
How can i customize a cell of Grid view with two textview, as i want to show 2 labels in each cell.
In my task, i am looking for the Grid View as a Table and it contains two various Values in each cell. i have Tried the Customized Grid view for this as follow.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button android:id="@+id/selectBtn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Select" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:minWidth="200px" />
<GridView android:id="@+id/PhoneGrid"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:numColumns="auto_fit" android:verticalSpacing="10dp"
android:horizontalSpacing="10dp" android:columnWidth="90dp"
android:stretchMode="columnWidth" android:gravity="center"
android:layout_above="@id/selectBtn" />
</RelativeLayout>
and the Custom layout is,..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/Name" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerInParent="true" />
<TextView android:id="@+id/Number" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
In this i need to display the name and phone number in a single Gridview..
Help me do get the Solution..
Thanks in Advance..
回答1:
Simply i have used a String with Multiline Processing as "\n"..
Like you can subsitude the String as follows
String header=first_String_Variable+"\n"+second_String_Variable;
and set grid by using Adapter..
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, header);
gridHeader.setAdapter(adapter);
回答2:
You want to create an Adapter class that extends BaseAdapter to pass into the GridView in code. Everything you need to do is already shelled out for you in the methods you need to override. Android has a decent tutorial that should help you get started. If you need help understanding what each part does just look it up on here. There are plenty of people who have went through the same thing you are going through now, so resources are in the plenty :)
Cheers.
回答3:
You can follow this link and can replace the place of imageview, you can use the Text, what you need..
Cusom GridView
Thank you
来源:https://stackoverflow.com/questions/13303064/how-to-create-customized-grid-view-with-two-textview