两个Activity之间的跳转
[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);
}
}
}
<?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>
</activity>
<activity android:name="com.example.android0420.MainMeunActicity" android:label="@string/mianmenuactivitytitle"/>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Android_2.2_0420</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="mianmenuactivity">您好,欢迎您!</string>
<string name="mianmenuactivitytitle">主界面</string>
</resources>