stellarowl12
stellarowl12

Reputation: 525

How to create a 'Table' in my Android app

So I'm trying to create a 2-column table in my Android app and am looking for advice on the best way to approach it.

This table will have a header above each column and the table itself might extend off the bottom of the screen. (Will need scrolling). One of the columns will be filled with text. The second column is filled with dropdown spinners.

I've tried multiple different ways but am not sure what's the canonical way to do this...Should I be using a Relative Layout? Should I be wrapping everything in a ScrollView? Should I just use a TableView with TableRows? Or should I be using a combination of multiple of these?

Note: I'd also like to be able to have "borders" in my table. Maybe just at the bottom of each row. I read somewhere to just put TextViews that fill the screen width-wise and have a height of like 2dp with a background color set. Will this approach work with what you are suggesting?

Thanks in advance for the advice!

Upvotes: 0

Views: 450

Answers (1)

Lamorak
Lamorak

Reputation: 11137

Seems like a job for captain ListView! You can addHeader that scrolls or wrap it in RelativeLayout with fixed header. You can just have divider between the rows created automatically. Your rows will be generated by an adapter. This is what row layout should look like

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <Spinner
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
</LinearLayout>

Upvotes: 1

Related Questions