首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

Android TabHost运用、动态加载内容

2012-08-22 
Android TabHost使用、动态加载内容使用TabHost有两种办法1.在layout的xml文件里定义,格式如下:其中TabHost

Android TabHost使用、动态加载内容
使用TabHost有两种办法
1.在layout的xml文件里定义,格式如下:


其中TabHost、TabWidget、FrameLayout的id必须如上,否则运行出错,甚至不能通过编译。
在代码中用
TabHost myTabHost = (TabHost) findViewById(R.id.tabhost);   TabWidget tabWidget = myTabHost.getTabWidget();  myTabHost.addTab(tabHost.newTabSpec("tab1")                   .setIndicator("tab1", getResources().getDrawable(R.drawable.mumule))                   .setContent(R.id.view1));  

使用Tab.
2.继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。
使用方法与上面类型。





1 楼 leehom16619 2010-10-26   # <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
#    android:id="@android:id/tabhost" 
#    android:layout_width="fill_parent" 
#    android:layout_height="fill_parent"> 
这里的id不能是@android:id/tabhost   应该是+id  不然怎么叫自定义tabhost 而且会出错
lz这样太误导新手了!!! 2 楼 GhostFromheaven 2010-11-03   leehom16619 写道# <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
#    android:id="@android:id/tabhost" 
#    android:layout_width="fill_parent" 
#    android:layout_height="fill_parent"> 
这里的id不能是@android:id/tabhost   应该是+id  不然怎么叫自定义tabhost 而且会出错
lz这样太误导新手了!!!
不能改为+id。具体参考Android自带开发文档。 3 楼 feng88724 2011-02-16   1楼的哥们别玩了~ 4 楼 GhostFromheaven 2011-02-18   feng88724 写道1楼的哥们别玩了~
刚接触总会有些不理解的地方的 5 楼 merman13 2011-03-30   1楼黑色幽默么。。。 6 楼 a90120411 2011-09-25   GhostFromheaven 写道leehom16619 写道# <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
#    android:id="@android:id/tabhost" 
#    android:layout_width="fill_parent" 
#    android:layout_height="fill_parent"> 
这里的id不能是@android:id/tabhost   应该是+id  不然怎么叫自定义tabhost 而且会出错
lz这样太误导新手了!!!
不能改为+id。具体参考Android自带开发文档。

请问如果不改成+id。TabHost myTabHost = (TabHost) findViewById(R.id.tabhost); 这句代码可以获取对象吗?求解惑。
   
    TabWidget tabWidget = myTabHost.getTabWidget();    //这句有什么意义呢?

   自定义的话应该tabhost应改成+id, 然后调用tabHost.setup();

参考文章: http://www.blogjava.net/freeman1984/archive/2009/11/18/302803.html

热点排行