如何增加一个activity

转自: http://blog.csdn.net/wangyuanwu/article/details/7053027

 

一、添加一个类文件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> 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值