Search code examples
androidandroid-linearlayouttablelayoutandroid-tablelayout

How to next child tablelayout android


I have a TableLayout within a ScrollView. I need to go to the next LinearLayout (dynamically created) which is within the TableView clicking a close button and return to the previous LinearLayout by clicking the back button.

Follow my XML as I am creating the TableView:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_weight="1">

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:id="@+id/myLayout"
        android:layout_height="match_parent"
    android:layout_weight="1">

        <android.support.v7.widget.Toolbar
            android:id="@+id/tb_pergunta"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize" />

        <ScrollView
            android:id="@+id/sv_table"
            android:layout_height="match_parent"
            android:scrollbars="horizontal|vertical"
            android:layout_width="match_parent"
            android:layout_marginTop="5dip"
            android:scrollbarStyle="outsideInset"
            android:fillViewport="true">

        <TableLayout
            android:id="@+id/tl_principal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </TableLayout>
    </ScrollView>
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="14">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ir para pergunta nº:"
            android:id="@+id/btnProximaPergunta"
            android:visibility="gone" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/botton_back"
            android:id="@+id/btnBackGroupExpandable" />

        <EditText
            android:layout_width="99dp"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/edtProximaPergunta"
            android:textAlignment="center" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/botton_next"
            android:id="@+id/btnNextGroupExpandable" />

    </LinearLayout>
</LinearLayout>

How can I do this?


Solution

  • You can give each LinearLayout a randomly generated ID as described here.

    Store those IDs in an array and then you can easily call any of them in any order.