<RelativeLayout 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" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="50dp" android:text="Current Show Form 1" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="62dp" android:text="Show Form 2" /> </RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="50dp" android:text="Current Show Form 2" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_centerHorizontal="true" android:layout_marginTop="62dp" android:text="Show Form 3" /> </RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="50dp" android:text="Current Show Form 3" android:textAppearance="?android:attr/textAppearanceLarge" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/textView3" android:layout_centerHorizontal="true" android:layout_marginTop="62dp" android:text="Back to Form 1" /> </RelativeLayout>
package com.myapp; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.app.Activity; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Default Show ShowConventView1() ShowConventView1(); } // Show activity_main.xml public void ShowConventView1() { setContentView(R.layout.activity_main); // Button1 final Button btn1 = (Button) findViewById(R.id.button1); // Perform action on click btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ShowConventView2(); } }); } // Show activity_form2.xml public void ShowConventView2() { setContentView(R.layout.activity_form2); // Show activity_form2 // Button2 final Button btn2 = (Button) findViewById(R.id.button2); // Perform action on click btn2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ShowConventView3(); } }); } // Show activity_form3.xml public void ShowConventView3() { setContentView(R.layout.activity_form3); // Show activity_form3 // Button3 final Button btn3 = (Button) findViewById(R.id.button3); // Perform action on click btn3.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ShowConventView1(); } }); } }
setContentView(R.layout.activity_main);
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท