2011-10-24 34 views
0

我所做的XML标记错误


你好,大家好,我试图创建一个自定义的ListView布局。我已经这样做了,但是我得到了一些XML标记错误: 在这一行发现多个注释: - 根元素后面的文档中的标记必须形成 - 。 - 错误:错误解析XML:文档元素

问题


像这对必须如何我自定义的ListView布局的样子,我不明白这些错误后的垃圾?在这里你找到代码:

<?xml version="1.0" encoding="utf-8" ?> 
<ListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="2" 
    android:drawSelectorOnTop="false"> 
</ListView> 
    <TextView 
     android:id="@+id/android:empty" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:text="No filter set" 
    </TextView> 

Thx提前为你的船员! 问候

野生动物园

回答

6

首先检查我已经包含在下面的XML布局中的所有评论,以便您更好地了解您错过了什么以及应该包含哪些内容。

布局应该是这样的:

<?xml version="1.0" encoding="utf-8" ?> 
    <!-- Root layout view should be there to include other 2 or more than 2 views --> 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" <!-- Android schema must be there in root layout --> 

     android:layout_width="match_parent" 
     android:layout_height="match_parent">  

    <ListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="2" 
     android:drawSelectorOnTop="false"> 

     <TextView 
      android:id="@+id/android:empty" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="No filter set"> <!-- You have missed to close the TextView tag ">" --> 
     </TextView> 
    </ListView> 
</LinearLayout> 
+1

THX为这个伟大的anwser! – safari

+0

@safari我相信你现在有想法。现在问题解决了吗? –

+1

是的,它解决了,我现在得到它是如何工作的,thx又一次! – safari

1

您必须声明xmlns:android="http://schemas.android.com/apk/res/android"您的根元素(实际使用android:someAttributeHere之前)

编辑:你必须有一个顶级元素(布局或<include />标签,将包装您两个布局元素)是这样的:

<?xml version="1.0" encoding="utf-8" ?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> 
<ListView 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="2" 
    android:drawSelectorOnTop="false"> 
</ListView> 
    <TextView 
     android:id="@+id/android:empty" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:text="No filter set" 
    </TextView> 
</LinearLayout> 
+0

在哪里我要声明这一点,因为当我把这个在我的ListView或TextView的我仍然得到一个错误 – safari

1

您应该添加xmlns:android="http://schemas.android.com/apk/res/android",并在你的XML格式的ViewGroup,含有这些两个v IEWS。

0

你缺少申报

的xmlns:安卓= “http://schemas.android.com/apk/res/android”

在列表视图