日期:2014-05-20  浏览次数:20712 次

Android中如何实现页面跳转
Android中怎样实现页面跳转啊?试了好多次,有时可以,但大多数时候总是会报错!下面是我写的一个小例子,在模拟器中运行的时候就会显示:应用程序意外停止!

下面是java代码:

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:id="@+id/titleView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:text="@string/titleLable"
  android:textAppearance="?android:attr/textAppearanceLarge"
  android:textColor="@color/titleCocle"
  android:textSize="30sp" />

  <Button
  android:id="@+id/timeButton"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:text="@string/timeLable"
  android:textColor="@color/textColor"
  android:textSize="25sp" />

</LinearLayout>

time.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:id="@+id/timeView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:text="@string/TimeLable"
  android:textAppearance="?android:attr/textAppearanceLarge"
  android:textColor="@color/titleCocle"
  android:textSize="30sp" />
   
  <TextView
  android:id="@+id/startView"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/timeStartLable"
  android:textAppearance="?android:attr/textAppearanceLarge" />
   
  <Button
  android:id="@+id/backButton"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="@string/backLable" />

</LinearLayout>


Liuxiuxiu02Activity.java

package lygtc.ruanjian.liuxiuxiu02;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Liuxiuxiu02Activity extends Activity implements OnClickListener{
  /** Called when the activity is first created. */
private Button timeButton;
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
   
  timeButton = (Button)findViewById(R.id.timeButton);
  timeButton.setOnClickListener(this);
  }
@Override