无法创建选项卡内容,因为在Android Eclipse中找不到id为-1 XML的视图错误?
我有一个包含TabHost的XML文件。我通过右键单击布局图->新建->Android XML->TabHost直接创建了它。代码似乎还可以,但每当我在Eclipse中转到图形布局时,它都会给我错误(请参阅标题)。我使用的是安卓2.2。这是我的XML代码:无法创建选项卡内容,因为在Android Eclipse中找不到id为-1 XML的视图错误?,android,xml,android-layout,tabs,android-tabhost,Android,Xml,Android Layout,Tabs,Android Tabhost,我有一个包含TabHost的XML文件。我通过右键单击布局图->新建->Android XML->TabHost直接创建了它。代码似乎还可以,但每当我在Eclipse中转到图形布局时,它都会给我错误(请参阅标题)。我使用的是安卓2.2。这是我的XML代码: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
<?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>
我刚刚提交了一份Android tools的文件: 以下用户和我在使用 布局编辑器的图形布局选项卡,即使在最简单和 正确的布局 “无法创建选项卡内容,因为找不到id为-1的视图” 当我将另一个xml文件作为选项卡时,我在API20中看到了它。如果 我复制并粘贴了include文件的内容,错误不存在 显示 有关此错误,请参阅以下其他报告: (见对raybritton的评论) 建议的答复)
我的解决方案是为每个选项卡的视图提供id。在下面的示例中,需要为每个textView指定id(如android:id=“@+id/tab1”…)
我的布局中的ADT20中也有这个。你的没有给我错误。您使用的是什么版本?我有最新的版本(我想是20.0.3),但我通过清理项目并重新启动eclipse解决了这个问题。在那之后,它工作得很好,显然有些布局文件没有正确加载或其他什么。
<?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>