Android Tab导航-ActivityGroup
2012-05-16 10:17:23 来源:WEB开发网核心提示:private Button button1; private Button button2;private LinearLayout container;private OnClickListener l = new OnClickListener(){@Overridepublic void onClick(Vie
private Button button1; private Button button2; private LinearLayout container; private OnClickListener l = new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.button1: switchActivity(0); break; case R.id.button2: switchActivity(1); break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button)findViewById(R.id.button1); button2 = (Button)findViewById(R.id.button2); container = (LinearLayout) findViewById(R.id.container); button1.setOnClickListener(l); button2.setOnClickListener(l); switchActivity(0); } private void switchActivity(int id){ container.removeAllViews(); Intent intent = null; switch(id){ case 0: intent = new Intent(this,TestActivity1.class); break; case 1: intent = new Intent(this,TestActivity2.class); break; } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Window subActivity = getLocalActivityManager().startActivity("subActivity", intent); container.addView(subActivity.getDecorView(),LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); }
<?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"> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="窗体1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="窗体2" /> </LinearLayout> <LinearLayout android:id="@+id/container" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#0000ff"> </LinearLayout> </LinearLayout>
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接