首先在在AndroidManifest.xml里配置
<!-- 添加第二个activity -->
<activity android:name=".OtherActivity" android:label="other Activity"></activity>
在第一个main layout里面配置一个跳转按钮
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="打开otheractivity"
android:id="@+id/button"
/>
配置第二个layout
<LinearLayout
xmlns:android="
http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:text="other activiy"
/>
</LinearLayout>
待跳转页面的activity,与第二个layout结合.代码如下
public class OtherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.other);
}
}
对主activity配置.点击button可以跳转到第二个页面
Button button = (Button)this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// 打开另一个activity,通过意图,意图作用是激活其他组件
Intent intent = new Intent();
intent.setClass(MainActivityActivity.this, OtherActivity.class);
//发送意图.将意图发送给android系统,系统根据意图来激活组件
startActivity(intent);
}
});
}