Q:

switching between layouts using setvisibility on android not working

I'm using a screen that I want to switch between layouts on the click of a button. I want both layouts to occupy the full height of the screen, when the button on the first layout is pressed, i want this layout to disappear and the other layout to take it's place, and then same on the next layout.
<LinearLayout 
    android:id="@+id/layoutFirst"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    ..... views

</LinearLayout>

<LinearLayout 
    android:id="@+id/layoutSecond"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    ..... views

</LinearLayout>

On each layout I have a button. I want this button to switch so the other layout occupies the full screen, but nothing happens. The code in the on-click event for the first screen is the following
LinearLayout layoutFirst = (LinearLayout) this.findViewById(R.id.layoutFirst);
layoutFirst.setVisibility(View.GONE);
LinearLayout layoutSecond = (LinearLayout) this.findViewById(R.id.layoutSecond);
layoutSecond.setVisibility(View.VISIBLE);

Just in case the problem was to do with the fill_parent, I also tried this with the height being set to wrap_content. Initially I can see both layouts on the screen, when I press the button, the layout still does nothing.
Can anyone tell me if I am doing something wrong or if there's a way to solve this issue. Any help would be greatly appreciated it

A:

Put the two LinearLayouts inside a FrameLayout:
<FrameLayout
    android:id="@+id/framelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/layoutFirst"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:visibility="gone">
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layoutSecond"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    </LinearLayout>
</FrameLayout>

Give the LinearLayouts different ids!

