PowenKo, Android Tutorial 018, Activity, Activity change page

August 26, 2011   ·   2 Comments

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

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (2)

  1. Jose Ullaguari

    Exelente tutorial.

    »
  2. admin-powenko

    thanks, Jose

    »

You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon