Imran Hakeem
Imran Hakeem

Reputation: 191

Need to make a gridview with two static text fields

Hello i need to make a gridview like the following images with static textviews.enter image description here

I need to make it in Portrait mode. I know there are lot of guides available on stackoverflow on how to make a gridview with two textviews but i am unable to follow them and failed many times trying to create a gridview exactly like this. Instead of marking my post as negative if someone could help me build a gridview like above i will be really great full. Thanks!

Edit: I have tried a TableLayout in order to achieve the above layout and things are going well except i cannot draw a vertical line(divider). See the image below:enter image description here

My Code:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:divider="#FF909090"
android:orientation="horizontal"
android:stretchColumns="1"
android:background="@drawable/custom_background"
android:showDividers="middle">
<TableRow>
    <TextView
        android:text="Name"
        android:padding="3dip" />
    <TextView
        android:text="Imran"
        android:gravity="left"
        android:padding="3dip" />
</TableRow>

<View
    android:layout_height="2dip"
    android:background="#FF909090" />

<TableRow>
    <TextView
        android:text="Name"
        android:padding="3dip" />

    <TextView
        android:text="Test"
        android:gravity="left"
        android:padding="3dip" />
</TableRow>

<View
    android:layout_height="2dip"
    android:background="#FF909090" />

<TableRow>
    <TextView
        android:text="Name"
        android:padding="3dip" />

    <TextView
        android:text="Test"
        android:gravity="left"
        android:padding="3dip" />
</TableRow>

Thanks to all for helping me out.

Upvotes: 0

Views: 48

Answers (1)

Kelevandos
Kelevandos

Reputation: 7082

I think your problem is in the assumption that you need to use a GridView here.

What you presented should be done with a ListView or, even better, a RecyclerView.

Try looking at each row as a list item and the task will become really easy :-)

Like this:

enter image description here

Upvotes: 1

Related Questions