Android 开发之 Activity 切换
2010-04-12 16:02:00 来源:WEB开发网private Button btn;
private Button btnClose;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.btnNextView);
btn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent itent=new Intent();
itent.setClass(ActivityChange.this, ActivitySecond.class);
startActivity(itent);
ActivityChange.this.finish();
}
});
btnClose=(Button)findViewById(R.id.btn_exit);
btnClose.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
finish();
}
});
}
}
main.xml代码
< ?xml version="1.0" encoding="utf-8"? >
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
< TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/ >
< Button
android:id="@+id/btnNextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/show_next"
/ >
< Button
android:id="@+id/btn_exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_close"
/ >
< /LinearLayout >
AndroidManifest.xml代码
< ?xml version="1.0" encoding="utf-8"? >
更多精彩
赞助商链接