1

I have two layouts that I want to change between each other when clicking a button. They are full screen views like this:

<FrameLayout 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:background="#FF0000"
tools:context=".FullscreenActivity" >

and I want them to change between them when clicking

 <Button
 android:id="@+id/green_button"
 style="?buttonBarButtonStyle"
 android:layout_width="0dp"
 android:layout_height="wrap_content"
 android:layout_weight="1"
 android:text="@string/green" />

Am I supposed to change something in src/com.example.layout/fullscreenactivity.java onClick() or where can I change so this happens?

Big thanks in advance

Komanti
  • 21
  • 4

5 Answers5

1
rb = (Button) findViewById(R.id.green_button);
rb.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
            setContentView(R.layout.OtherLayout);
// now in order to use other layout button, image or any child function you have to declare it under the                 setContentView(R.layout.OtherLayout);

    }
});

please do accept the answer :)

Kosh
  • 6,140
  • 3
  • 36
  • 67
0

Easiest way would be having both FrameLayouts applied, and in onClickListener only change visibility of one to visible and the other to gone

slezadav
  • 6,104
  • 7
  • 40
  • 61
0

Yes, in your activity where you utilize the framelayout and the button, you will have to add a listener for the button and the appropriate actions to happen when the button is clicked (in your case - change the layout)

geeky_chik
  • 28
  • 1
  • 5
0

One thing you can do is to declare both layouts in one xml file and then use setVisibility(View.GONE) to remove particular layout. You can see this in this stackoverflow question.

Community
  • 1
  • 1
android guy
  • 108
  • 5
0
layout1 = (FrameLayout)findViewById(R.id.frameLayout1);
layout2 = (FrameLayout)findViewById(R.id.frameLayout2);
layout2.setVisibility(View.GONE);
mButton = (Button)findViewById(R.id.green_button);

mButton.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
            layout1.setVisibility(View.GONE);
            layout2.setVisibility(View.VISIBLE);

    }
});
Swayam
  • 16,294
  • 14
  • 64
  • 102