add new a page2layout.xml

setup the name “page2layout.xml”

update “main.xml”

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<Button
	android:text="Button"
	android:id="@+id/button1"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"></Button>

</LinearLayout>

update “page2layout.xml”

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="page2"
    />

</LinearLayout>

update Tutorial_Activity_ActivityActivity.java

package com.powenko.Tutorial_Activity_Activity;

import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Tutorial_Activity_ActivityActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button b1 = (Button) findViewById(R.id.button1);
        b1.setOnClickListener(new Button.OnClickListener()
        {
          public void onClick(View v)
          {

            Intent intent = new Intent();
        	  intent.setClass(Tutorial_Activity_ActivityActivity.this, page2.class);

        	  startActivity(intent);
        	  Tutorial_Activity_ActivityActivity.this.finish();
          }
        });

    }
}

add  new Class

setup name “page2”

update page2.java


package com.powenko.Tutorial_Activity_Activity;

import android.app.Activity;
import android.os.Bundle;

public class page2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.page2layout);

    }
}

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.powenko.Tutorial_Activity_Activity"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="3" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Tutorial_Activity_ActivityActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="page2" ></activity>

    </application>

</manifest>

sample code:

Tutorial_Activity_Activity

By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is www.looptek.com

Leave a Reply