两个Activity其间的跳转
两个Activity之间的跳转
[img=http://pan.baidu.com/share/link?shareid=426765&uk=907568367][/img]代码如下:
MainActivity
AndroidMainfest.xml
[img=http://pan.baidu.com/share/link?shareid=426765&uk=907568367][/img]代码如下:
MainActivity
package com.example.android0420;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tvuser=(TextView)findViewById(R.id.TextViewUser);
TextView tvpass=(TextView)findViewById(R.id.TextViewPass);
Button blogin=(Button)findViewById(R.id.ButtonLogin);
Button bexit=(Button)findViewById(R.id.ButtonExit);
tvuser.setText("用 户:");
tvpass.setText("密 码:");
blogin.setText("登 录");
bexit.setText("退 出");
blogin.setOnClickListener(new MyButtonListener());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
class MyButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setClass(MainActivity.this, MainMeunActivity.class);
MainActivity.this.startActivity(intent);
}
}
}
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android0420"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.android0420.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>