enginar
enginar

Reputation: 307

Framelayout call new activity when click button

i have a layout and there is a framelayout in this.

i put 2 buttons. and i wanna call activity1 in framelayout when click button1. and so click button2 call activity2 in framelayout.

is this possible?

layout1.xml

  <Button
                android:id="@+id/button1"
                android:layout_width="80dp"
                android:layout_height="35dp"
                android:background="@drawable/tab_buton"
                android:text="@string/turlar"
                android:textColor="#ffffff"
                android:textSize="12sp"
                android:textStyle="bold" android:layout_weight="1"/>

            <Button
                android:id="@+id/button2"
                android:layout_width="80dp"
                android:layout_height="35dp"
                android:background="@drawable/tab_buton"
                android:text="@string/alisveris"
                android:textColor="#ffffff"
                android:textSize="12sp"
                android:textStyle="bold" android:layout_weight="1"/>
        </LinearLayout>



<FrameLayout
    android:id="@+id/frameLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/linearLayout2"
    android:layout_marginLeft="5dp"
    android:layout_weight="0.59" android:layout_marginRight="5dp">
</FrameLayout>

activity1.java

public class Firsat extends Base {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout1);

}

when i click button1 call another activity in framlayout.

Upvotes: 0

Views: 832

Answers (2)

Akhil
Akhil

Reputation: 14058

No, that is not possible. Activities can't be nested. Opening activity 2 will pust Activity 1 to the backstack. You can use fragments for the job though.

Upvotes: 1

Simone Casagranda
Simone Casagranda

Reputation: 1215

I think that don't have a clear idea about the difference between an activity and a layout.

A layout, referring to .xml, is something that defines how build your UI, positioning views inside your screen. An activity is a container that works as controller to interact with your screen, data, ... and that can reflect operation on your layout layout.

So if you have two frame in your FrameLayout you can use only one activity, hiding and showing frames after button click.

Upvotes: 1

Related Questions