无法创建选项卡的内容,因为找不到视图ID为-1 XML错误在Android中的Eclipse? [英] Could not create tab content because could not find view with id -1 XML error in Android Eclipse?

查看:1097
本文介绍了无法创建选项卡的内容,因为找不到视图ID为-1 XML错误在Android中的Eclipse?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个TabHost的XM​​L文件。 >新 - - > Android的XML - > TabHost我通过右键单击布局图创建它直接。在code似乎是确定,但每当我去图形布局在Eclipse中,它给我的错误(见标题)。我使用的是Android 2.2的。这是我的XML code:

 <?XML版本=1.0编码=UTF-8&GT?;< TabHost的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@机器人:ID / tabhost
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>    <的LinearLayout
        机器人:ID =@ + ID / linearLayout1
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:方向=垂直>        < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT>
        < / TabWidget>        <的FrameLayout
            机器人:ID =@机器人:ID / tabcontent
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent>            <的LinearLayout
                机器人:ID =@ + ID / TAB1
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent>
            < / LinearLayout中>            <的LinearLayout
                机器人:ID =@ + ID / TAB2
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent>
            < / LinearLayout中>            <的LinearLayout
                机器人:ID =@ + ID / TAB3
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent>
            < / LinearLayout中>
        < /&的FrameLayout GT;
    < / LinearLayout中>< / TabHost>


解决方案

我是给ID为每个选项卡的视图解决方案。在下面的例子中,有必要给ID给每个TextView的(如Android:ID =@ + ID / TAB1...)

 <?XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
    < TabWidget
        机器人:ID =@机器人:ID /标签
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT>        <的TextView
            机器人:标签=TAB1
            机器人:文字=@字符串/ TAB1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =FILL_PARENT
            机器人:TEXTSIZE =12SP
            />
        <的TextView
            机器人:标签=TAB2
            机器人:文字=@字符串/ TAB2
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =FILL_PARENT
            机器人:TEXTSIZE =12SP
            />
        <的TextView
            机器人:标签=TAB3
            机器人:文字=@字符串/ TAB3
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =FILL_PARENT
            机器人:TEXTSIZE =12SP
            />
        <的TextView
            机器人:标签=TAB4
            机器人:文字=@字符串/ TAB4
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =FILL_PARENT
            机器人:TEXTSIZE =12SP
            />
        <的TextView
            机器人:标签=tab5
            机器人:文字=@字符串/ tab5
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =FILL_PARENT
            机器人:TEXTSIZE =12SP
            />    < / TabWidget>    <的FrameLayout
        机器人:ID =@机器人:ID / tabcontent
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT>        <的TextView
            机器人:ID =@ + ID / TAB1
            机器人:文字=Hallo3
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT/>
        <的TextView
            机器人:ID =@ + ID / TAB2
            机器人:文字=Hallo2
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT/>
        <的TextView
            机器人:ID =@ + ID / TAB3
            机器人:文字=Hallo3
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT/>
        <的TextView
            机器人:ID =@ + ID / TAB4
            机器人:文字=Hallo3
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT/>
        <的TextView
            机器人:ID =@ + ID / tab5
            机器人:文字=Hallo3
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT/>    < /&的FrameLayout GT;
< / LinearLayout中>
< / TabHost>

I have an XML file which contains a TabHost. I created it directly by right clicking the layout map -> new -> Android XML -> TabHost. The code seems to be ok but whenever I go to graphical layout in Eclipse, it gives me the error (see the title). I'm using Android 2.2. This is my XML code:

<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <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="match_parent" >

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>

</TabHost>

解决方案

The solution for me was giving id to each tab's view. In the following example there was a need to give id to each textView (like android:id="@+id/tab1" ...)

<?xml version="1.0" encoding="utf-8"?>
<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">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView
            android:tag="tab1"
            android:text="@string/tab1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:textSize="12sp"
            />
        <TextView
            android:tag="tab2"
            android:text="@string/tab2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:textSize="12sp"
            />
        <TextView
            android:tag="tab3"
            android:text="@string/tab3"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:textSize="12sp"
            />
        <TextView
            android:tag="tab4"
            android:text="@string/tab4"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:textSize="12sp"
            />
        <TextView
            android:tag="tab5"
            android:text="@string/tab5"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:textSize="12sp"
            />

    </TabWidget>

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView
            android:id="@+id/tab1"
            android:text="Hallo3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <TextView
            android:id="@+id/tab2"
            android:text="Hallo2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <TextView
            android:id="@+id/tab3"
            android:text="Hallo3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <TextView
            android:id="@+id/tab4"
            android:text="Hallo3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
        <TextView
            android:id="@+id/tab5"
            android:text="Hallo3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </FrameLayout>
</LinearLayout>
</TabHost>

这篇关于无法创建选项卡的内容,因为找不到视图ID为-1 XML错误在Android中的Eclipse?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆