添加一个新的Activity

 一、添加一个类文件otherActivity

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

public class OtherActivity extends Activity

{
 private TextView myTextView = null;
 @Override
 protected void onCreate(Bundle savedInstanceState)

 {
       // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.other);
  //取得从上一个Activity当中传递过来的Intent对象
  Intent intent = getIntent();
  //从Intent当中根据key取得value
  String value = intent.getStringExtra("testIntent");
  //根据控件的ID得到响应的控件对象
  myTextView = (TextView)findViewById(R.id.myTextView);
  //为控件设置Text值
  myTextView.setText(value);
  
     }

}

二、layout中添加布局文件other.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 该文件是OtherActivity.java文件所使用的布局文件 -->
<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:id="@+id/myTextView"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 />
</LinearLayout>

三、在manifest中配置注册

<?xml version="1.0" encoding="utf-8"?>
<!-- 在该应用程序当中注册了两个Activity -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="mars.activity02"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
     <!-- 这个Activity是应用程序启动时第一个要运行的Activity -->
        <activity android:name=".Activity02"
                  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的配置 -->
  <activity android:name=".OtherActivity" android:label="@string/other"/>
    </application>
    <uses-sdk android:minSdkVersion="4" />

</manifest> 

posted @ 2014-10-23 10:03  HelloZQP  阅读(93)  评论(0)    收藏  举报