要完成兩個頁面之間的跳轉,(單擊頁面1中的跳轉按鈕,跳轉到頁面2)如圖:
======〉〉〉
在layout文件夾中的xml文件
hello.xml文件
regist.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="match_parent"
android:layout_height="wrap_content"
android:text="@string/name"
/>
<EditText
android:id="@+id/uname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:hint="@string/uname"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/password"
/>
<EditText
android:id="@+id/pwd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:hint="@string/pwd"
android:inputType="textPassword"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button2" />
</LinearLayout>
</LinearLayout>
AndroidManifest.xml文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.derun.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".HelloWorldActivity" android:label="Hello">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".Regist" android:label="register"></activity>
</application>
</manifest>
java代碼:(事件偵聽)
HelloWorldActivity .java文件
public class HelloWorldActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.hello);
Button button=(Button)findViewById(R.id.button3);
button.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent intent=new Intent(HelloWorldActivity.this,Regist.class);
startActivity(intent);
}
});
}
}
Regist .java文件
public class Regist extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.regist);
}
}