PowenKo, Android Tutorial 018-1, Activity, change page and pass data t next page.

August 26, 2011   ·   0 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"
    />
<TextView 
	android:text="TextView" 
	android:id="@+id/textView1" 
	android:layout_width="wrap_content" 
	android:layout_height="wrap_content"></TextView>
    
</LinearLayout>




update Tutorial_Activity_ActivityIntentStringActivity.java

package com.powenko.Tutorial_Activity_ActivityIntentString;


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

public class Tutorial_Activity_ActivityIntentStringActivity 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_ActivityIntentStringActivity.this, page2.class);
        	  
        	  Bundle bundle=new Bundle();
        	  bundle.putInt("intvlaue", 1);
        	  bundle.putString("Web", "www.powenko.com");        	
        	  intent.putExtras(bundle);
        	  
        	  startActivity(intent);
        	  Tutorial_Activity_ActivityIntentStringActivity.this.finish();
          }
        });
        
        
    }
}

add  new Class

setup name “page2″

update page2.java

package com.powenko.Tutorial_Activity_ActivityIntentString;



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



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);
        Bundle bundle= this.getIntent().getExtras();
        int t_value=bundle.getInt("intvlaue");
        String t_web=bundle.getString("Web");
        

        TextView t_textView_title = (TextView)findViewById(R.id.textView1);
        t_textView_title.setText(t_web+ t_value);
        
    }
}

AndroidManifest.xml

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Tutorial_Activity_ActivityIntentStringActivity"
                  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_ActivityIntentString

more information:

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

Tags: , , ,


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon