现在的位置: 首页 > 综合 > 正文

android TabHost setcontent出错

2013年10月11日 ⁄ 综合 ⁄ 共 627字 ⁄ 字号 评论关闭

一直出错,试了网上的方法都不行,就是一直返回null  日你个JAVA

tabHost=(TabHost) findViewById(android.R.id.tabhost);
        tabHost.setup();//最后发现要加上这句,大概意思就是初始化Tab吧
        TabSpec tab1=tabHost.newTabSpec("Tab1").setIndicator("Tab 1", getResources().getDrawable(R.drawable.icon))
        .setContent(R.id.textview1);

接着又出现一个错误

1.    LinearLayout tempLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.table_tab, null);  
 2.       TabHost.TabSpec tabItem = tabHost.newTabSpec("bb");
  3.      tabItem.setIndicator(tempLayout);

4.tabItem.setContent(R.id.table_gridView);

5.tabHost.addTab(tabItem);

在最后一行第5行出错

先入为主以为又是 seContent,有parent

最后发现又变成setIndicator的问题,tempLayout不能有parent

抱歉!评论已关闭.