源码:
http://download.csdn.net/detail/jzp12/4326106
本章是后面文章的基础,只涉及activity之间的跳转,不涉及activity之间参数传递。
1)在src下建立3个activity和在res/layout下建立3个xml分别是:
SwitchMulActivityActivity --- main.xml
Changshahome --- changshahome.xml
Shanghaihome --- shanghaihome.xml
注意事项:
1,xml文件的名称必须是小写
2,新建activity,SuperClass栏目中应该输入或者选择android.app.Activity
3,可通过自动在AndroidManifest.xml中添加两个activity,或者直接在AndroidManifest.xml添加代码实现。
2)直接上代码:
SwitchMulActivityActivity.java
Changshahome.java
Shanghaihome.java
main.xml
changshahome.xml
shanghaihome.xml
2)效果图:
参考:Android开发循序渐进实例1--资源文件设计以及画面跳转例子
http://blog.csdn.net/jackxinxu2100/article/details/5257186
Activity的跳转与传值
http://android.blog.51cto.com/268543/323982
本章是后面文章的基础,只涉及activity之间的跳转,不涉及activity之间参数传递。
1)在src下建立3个activity和在res/layout下建立3个xml分别是:
SwitchMulActivityActivity --- main.xml
Changshahome --- changshahome.xml
Shanghaihome --- shanghaihome.xml
注意事项:
1,xml文件的名称必须是小写
2,新建activity,SuperClass栏目中应该输入或者选择android.app.Activity
3,可通过自动在AndroidManifest.xml中添加两个activity,或者直接在AndroidManifest.xml添加代码实现。
2)直接上代码:
SwitchMulActivityActivity.java
package lostman.rigortek.china;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.content.Intent;
import android.view.View;
public class SwitchMulActivityActivity extends Activity {
private Button cbtGoChangsha;
private Button cbtGoShanghai;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cbtGoChangsha = (Button) findViewById(R.id.gochangsha);
cbtGoShanghai = (Button) findViewById(R.id.goshanghai);
do{
if(null == cbtGoChangsha || null == cbtGoShanghai){
break;
}
cbtGoChangsha.setOnClickListener(new Button.OnClickListener() {
//实现监听器接口的匿名内部类,其中监听器本身是View类的内部接口
//实现接口必须实现的onClick方法
@Override
public void onClick(View v) {
Intent cSwitchIntent = new Intent();
if(null != cSwitchIntent){
cSwitchIntent.setClass(SwitchMulActivityActivity.this,Changshahome.class);
startActivity(cSwitchIntent);
//SwitchMulActivityActivity.this.finish();
}
}
});
cbtGoShanghai.setOnClickListener(new Button.OnClickListener() {
//实现监听器接口的匿名内部类,其中监听器本身是View类的内部接口
//实现接口必须实现的onClick方法
@Override
public void onClick(View v) {
Intent cSwitchIntent = new Intent();
if(null != cSwitchIntent){
cSwitchIntent.setClass(SwitchMulActivityActivity.this,Shanghaihome.class);
startActivity(cSwitchIntent);
//SwitchMulActivityActivity.this.finish();
}
}
});
}while(false);
}
}
Changshahome.java
package lostman.rigortek.china;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Changshahome extends Activity {
private Button cbtGoBasehome;
private Button cbtGoShanghai;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.changshahome);
cbtGoBasehome = (Button) findViewById(R.id.gobasehome);
cbtGoShanghai = (Button) findViewById(R.id.goshanghai);
do{
if(null == cbtGoBasehome ||null == cbtGoShanghai){
break;
}
cbtGoBasehome.setOnClickListener(new Button.OnClickListener() {
//实现监听器接口的匿名内部类,其中监听器本身是View类的内部接口
//实现接口必须实现的onClick方法
@Override
public void onClick(View v) {
Intent cSwitchIntent = new Intent();
if(null != cSwitchIntent){
cSwitchIntent.setClass(Changshahome.this, SwitchMulActivityActivity.class);
startActivity(cSwitchIntent);
//Changshahome.this.finish();
}
}
});
cbtGoShanghai.setOnClickListener(new Button.OnClickListener() {
//实现监听器接口的匿名内部类,其中监听器本身是View类的内部接口
//实现接口必须实现的onClick方法
@Override
public void onClick(View v) {
Intent cSwitchIntent = new Intent();
if(null != cSwitchIntent){
cSwitchIntent.setClass(Changshahome.this, Shanghaihome.class);
startActivity(cSwitchIntent);
//Changshahome.this.finish();
}
}
});
}while(false);
}
}
Shanghaihome.java
package lostman.rigortek.china;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Shanghaihome extends Activity {
private Button cbtGoBasehome;
private Button cbtGoShanghai;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.shanghaihome);
cbtGoBasehome = (Button) findViewById(R.id.gobasehome);
cbtGoShanghai = (Button) findViewById(R.id.gochangsha);
do{
if(null == cbtGoBasehome || null == cbtGoShanghai){
break;
}
cbtGoBasehome.setOnClickListener(new Button.OnClickListener() {
//实现监听器接口的匿名内部类,其中监听器本身是View类的内部接口
//实现接口必须实现的onClick方法
@Override
public void onClick(View v) {
Intent cSwitchIntent = new Intent();
if(null != cSwitchIntent){
cSwitchIntent.setClass(Shanghaihome.this, SwitchMulActivityActivity.class);
startActivity(cSwitchIntent);
//Shanghaihome.this.finish();
}
}
});
cbtGoShanghai.setOnClickListener(new Button.OnClickListener() {
//实现监听器接口的匿名内部类,其中监听器本身是View类的内部接口
//实现接口必须实现的onClick方法
@Override
public void onClick(View v) {
Intent cSwitchIntent = new Intent();
if(null != cSwitchIntent){
cSwitchIntent.setClass(Shanghaihome.this, Changshahome.class);
startActivity(cSwitchIntent);
//Shanghaihome.this.finish();
}
}
});
}while(false);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ff0000"
android:background="#ffffff"
android:textSize="20dp"
android:text="@string/Basehome"
android:gravity="center"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:layout_marginTop="10dp"
>
<Button
android:id="@+id/gochangsha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SwitchToChangshahome"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"/>
<Button
android:id="@+id/goshanghai"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SwitchToShanghaihome"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
</LinearLayout>
changshahome.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00ff00"
android:background="#ffffff"
android:textSize="20dip"
android:text="@string/Changsha"
android:gravity="center"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:layout_marginTop="10dp"
>
<Button
android:id="@+id/gobasehome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SwitchToBasehome"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"/>
<Button
android:id="@+id/goshanghai"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SwitchToShanghaihome"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
</LinearLayout>
shanghaihome.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#0000ff"
android:background="#ffffff"
android:textSize="20dip"
android:text="@string/Shanghai"
android:gravity="center"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:layout_marginTop="10dp"
>
<Button
android:id="@+id/gobasehome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SwitchToBasehome"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"/>
<Button
android:id="@+id/gochangsha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SwitchToChangshahome"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
</LinearLayout>
2)效果图:
![](https://img-my.csdn.net/uploads/201205/24/1337826810_2131.jpg)
![](https://img-my.csdn.net/uploads/201205/24/1337826814_1746.jpg)
![](https://img-my.csdn.net/uploads/201205/24/1337826822_4913.jpg)
参考:Android开发循序渐进实例1--资源文件设计以及画面跳转例子
http://blog.csdn.net/jackxinxu2100/article/details/5257186
Activity的跳转与传值
http://android.blog.51cto.com/268543/323982