I am trying to create a basic datasheet in my application using a TableLayout. The first row contains the titles of each column. Every row thereafter is data. I would like the data to be scrollable while keeping the first title row visible (i.e. the first row would not scroll with the rest).
I have tried something like the following (unsuccessfully):
<TableLayout>
<TableRow>
<!-- The headers -->
<TextView android:text="Header #1"/>
<TextView android:text="Header #2"/>
<TextView android:text="Header #3"/>
</TableRow>
<ScrollView>
<!--The rest of the data -->
<TableRow>
<TableRow>
...
</ScrollView>
</TableLayout>
This causes the program to crash. Any other suggestions?
It crashes because you can only have
TableRows as direct descendants in aTableLayout.What you probably want to use is a
ListViewand a ‘header’ above it.Example (not complete):
The key is the
layout_weight="1"and theandroid:layout_width="fill_parent"that will give you 3 views of equal size. You’ll then need to create anAdapterand in your custom layout provided by theAdapterdo the same thing for the child views. You might have to fiddle slightly with the padding/margins for them to line up horizontally exactly.