1#
项目demo可去安卓开发qq群273843464下载
首先是src的中的.java文件 一个.java文件对应一个view,并且一个view有一个界面的xml

public class Activity01 extends Activity
{
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v)
            {
                Intent intent = new Intent();
                intent.setClass(Activity01.this, Activity02.class);
                startActivity(intent);
                Activity01.this.finish();
            }
        });
    }
}
Activity01

切换时候实例化一个intent对象,用setClass的方法进行切换从activity1类切换到activity2类中

public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main2);
        /* findViewById(R.id.button2)ȡ�ò���main.xml�е�button2 */
        Button button = (Button) findViewById(R.id.button2);

        button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v)
            {

                Intent intent = new Intent();
                intent.setClass(Activity02.this, Activity01.class);
                startActivity(intent);
                Activity02.this.finish();
            }
        });
    }
然后是样式xml


    androidrientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
          android:id="@+id/button1"
      android:layout_width="100px"
      android:layout_height="wrap_content"
      android:layout_x="100px"
      android:layout_y="80px"
      android:text="切换"
    >
    

样式2


    androidrientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello2"
    >
    
          android:id="@+id/button2"
      android:layout_width="100px"
      android:layout_height="wrap_content"
      android:layout_x="100px"
      android:layout_y="80px"
      android:text="切换"
    >