源码: 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

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方法@Overridepublic 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方法@Overridepublic 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;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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方法@Overridepublic 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方法@Overridepublic 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;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.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方法@Overridepublic 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方法@Overridepublic 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)效果图:






参考:Android开发循序渐进实例1--资源文件设计以及画面跳转例子
http://blog.csdn.net/jackxinxu2100/article/details/5257186
Activity的跳转与传值
http://android.blog.51cto.com/268543/323982

更多相关文章

  1. Android(安卓)Handler导致内存泄漏的解决方案
  2. 【开源项目12】Retrofit – Java(Android) 的REST 接口封装类库
  3. Android(安卓)地理编码&逆地理编码(百度、阿里接口对比)
  4. Android(安卓)LCD(二):LCD常用接口原理篇
  5. [转载] android中的surface
  6. android网络传输的传送对象
  7. android webview中使用Java调用JavaScript方法并获取返回值
  8. Android基础之通过 Intent 传递类对象
  9. Android编程: 界面组成、事件监听器

随机推荐

  1. android studio升级方法
  2. Android TextView中的文字自动生成链接
  3. Android 开发环境配置
  4. 相对布局常用属性介绍(RelativeLayout)
  5. Android(安卓)TTS学习——TTS初体验
  6. Android(安卓)Message机制的灵活应用
  7. Android 学习笔记(十六):Widget-进度条
  8. android:EditText属性
  9. android中的帧动画
  10. Android 查看源码