0

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!

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Hmm this seems to do the trick! So each linear layout here represents a single row right? Also would these dividers just be textviews or what do you recommend?
You only need to set some drawable and height. This can be done in your xml with divider parameter. Your drawable can even be simple color, for example android:divider="#333333".
A lots of info can be found here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.