android 使用Tabhost 发生could not create tab content because could not find view with id 错
来源:互联网 发布:在淘宝上如何开店步骤 编辑:程序博客网 时间:2024/06/06 14:08
使用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: ""
- OpenCV2马拉松第12圈——直方图比较
- ZOJ 3516 Tree of Three
- C++函数名字的隐藏:重写、重载、重定义
- TIPTOP中的圖形
- 区域和ANSI代码页(ACP, ANSI Code Page)
- android 使用Tabhost 发生could not create tab content because could not find view with id 错
- 21天战拖记——Day7:不要懒惰,继续加油!(2014-05-10)
- 二维几何
- java List 去重(两种方式)
- srping mvc RequestMapping实现
- 运用El表达式截取字符串/获取list的长度
- Leetcode: 4Sum
- HDU 1061 Rightmost Digit
- Java实现捕鱼达人附源码