tags:

views:

35

answers:

1

I have a TableLayout defined in my xml with three columns and four rows plus a heading row. Each column contains a TextView.

    <TableLayout
    android:id="@+id/inventory"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*"
    <TableRow>
        <TextView
            android:text="Item"/>
        <TextView
            android:text="Quantity"/>
        <TextView
            android:text="Units"/>
    </TableRow>
    <TableRow>
        <TextView
            android:id="@+id/inventorycell10"
        <TextView
            android:id="@+id/inventorycell11"
        <TextView
            android:id="@+id/inventorycell12"
    </TableRow>
    <TableRow>
        <TextView
            android:id="@+id/inventorycell20"
        <TextView
            android:id="@+id/inventorycell21"
        <TextView
            android:id="@+id/inventorycell22"
    </TableRow>
    <TableRow>
        <TextView
            android:id="@+id/inventorycell30"
        <TextView
            android:id="@+id/inventorycell31"
        <TextView
            android:id="@+id/inventorycell32"
    </TableRow>
    <TableRow>
        <TextView
            android:id="@+id/inventorycell40"
        <TextView
            android:id="@+id/inventorycell41"
        <TextView
            android:id="@+id/inventorycell42"
    </TableRow>
</TableLayout>

Is there any way of referring to the TextViews in code, without having to id them individually. I was thinking there might be come way of getting row/col views from the tableview.

-Frink

+3  A: 

You can use ViewGroup#getChildAt and ViewGroup#getChildCount. getChildAt on your root TableLayout will allow you to get the TableRows and subsequently calling it on the TableRows will allow you to access the TextViews.

Qberticus
Thanks for that. I've not tried it yet, but thanks Qberticus for your answer
FrinkTheBrave