android 使用Tabhost 发生could not create tab content because could not find view with id 错...
来源:互联网 发布:网络活动论坛 编辑:程序博客网 时间:2024/06/06 07:59
使用Tabhost的时候经常报:could not create tab content because could not find view with id 错误。
总结一下发生错误的原因,一般的发生在
setContent();
先看XML布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <TabHost android:id="@+id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" >
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent">
<TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="wrap_content" > </FrameLayout>
</RelativeLayout>
</TabHost></RelativeLayout>
代码:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sign_core); TabHost tabHost = (TabHost) findViewById(R.id.tabhost); tabHost.setup(); Intent intent = new Intent(this, TestActivity.class); TabSpec tab1 = tabHost.newTabSpec("A").setIndicator("A") .setContent(intent); tabHost.addTab(tab1); }
1、ID问题
必须为系统自带的ID android:id="@android:id/tabcontent"
2、Tabhost没有初始化
必须调用 tabHost.setup(); 方法初始化
3、 setContent(int viewID); 这里的参数是ID,如果出入R.layout.xxxx 一定报错
4、 setContent(Intent intent); 必须以下面的方式初始化Tabhost,否则报错。
LocalActivityManager localActivityManager = new LocalActivityManager(this, true); localActivityManager.dispatchCreate(savedInstanceState); TabHost tabHost = (TabHost) findViewById(R.id.tabhost); tabHost.setup(localActivityManager);
5、检查AndroidManifest.xml 配置文件有没有配置Intent的Activity
6、Intent的Activity本身存在错误,打断点看看有没有跳进来
0 0
- android 使用Tabhost 发生could not create tab content because could not find view with id 错
- android 使用Tabhost 发生could not create tab content because could not find view with id 错...
- android 使用Tabhost 发生could not create tab content because could not find view with id 错...
- Android使用TabHost程序异常终止could not create tab content because could not find view with id 错误
- 报错:Could not find method android.view.ViewTreeObserver.removeOnGlobalLayoutListener
- Eclipse使用问题—svn Could not create the view
- Eclipse使用问题—svn Could not create the view
- RFT 'Could not create the view: ' 解决办法
- Eclipse:Could not create the view:解决办法
- Eclipse:Could not create the view:解决办法
- Android.Could not find *.apk
- [Android]IllegalStateException: Could not find method onBind(View)
- Error:Could not find wechat-sdk-android-with-mta.jar
- Could not create JarEntryRevision
- could not create /tmp
- Could not create JarEntryRevision
- Could not create JarEntryRevision
- Android Logcat 报错:Could not create the view: For input string: ""
- 第七周项目6 计算一周的工资
- 黑马程序员--代理+AOP--实现一个类似spring的可配置的简单AOP框架
- dumpsys activity
- select、poll、epoll之间的区别总结[整理]
- 倒闸操作
- android 使用Tabhost 发生could not create tab content because could not find view with id 错...
- Eclipse中LogCat不刷新怎么办
- iOS 73 (Dev) 问题解决:UIViewController之间push操作时,iOS7中NavBar右侧有一块暗色出现
- list利用迭代器迭代
- php 换行符 PHP_EOL
- ctags 的使用
- 管道编程
- 链表
- Spring MVC