Reputation: 51
I am fairly new to this Android application thing and have a couple questions involving onclick listeners.
Right now I have a table inside a ScrollView with one column that includes several buttons. My goal is to get to a point where I can click on a button and then a second table would come up right next to the first (same layout as the first) but with a different set of buttons. Can someone please guide me in the right direction.
Let me know if you have any questions.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation='vertical' >
<ScrollView
android:layout_width="125dp"
android:layout_height="200dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout android:id="@+id/table_right"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow android:id="@+id/row_1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/Button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:textSize="20dp" >
</Button>
</TableRow>
<TableRow android:id="@+id/row_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button android:id="@+id/Button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:textSize="25dp" >
</Button>
</TableRow>
<TableRow android:id="@+id/row_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button android:id="@+id/Button_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 3"
android:textSize="25dp" >
</Button>
</TableRow>
<TableRow android:id="@+id/row_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button android:id="@+id/Button_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 4"
android:textSize="25dp" >
</Button>
</TableRow>
<TableRow android:id="@+id/row_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button android:id="@+id/Button_5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 5"
android:textSize="25dp" >
</Button>
</TableRow>
<TableRow android:id="@+id/row_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button android:id="@+id/Button_6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 6"
android:textSize="25dp" >
</Button>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Upvotes: 2
Views: 110
Reputation: 6334
to toggle the table between visible and invisible will i'll recommend you to use this follow here my example :-
boolean visible = true;
private void showHide() {
if (visible) {
if(table1.getVisibility() == View.Invisible ); {
table1.setVisibility(View.Visible)
}
}else table1.setVisibility(View.Invisible);
visible = !visible;
}
and on your button
.setOnClickListener
add showHide();
now when you click the button it will show table1
and when you click it again it will hide it. hope that helped you.
Upvotes: 1
Reputation: 5786
In the layout XML file, create both tables... but set the second table's visibility to "GONE". A visibility of GONE means that it won't even take any space in the layout.
I'm assuming you know how to execute some code when a button is pressed (if not, look up onclicklistener or the android:onClick xml shortcut). When the appropriate button is pressed, set the second table's visiblity to VISIBLE and it'll appear.
Upvotes: 1