XML标记错误

时间:2011-10-24 07:02:47

标签: android xml

我做了什么


Hello Guys,我正在尝试创建自定义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>
提前为您的冬天做好准备! 最诚挚的问候

狩猎

4 个答案:

答案 0 :(得分: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 :(得分: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>

答案 2 :(得分:1)

您应该添加xmlns:android="http://schemas.android.com/apk/res/android"并在xml中包含ViewGroup,其中包含这两个视图。

答案 3 :(得分:0)

你缺席宣布

的xmlns:机器人= “http://schemas.android.com/apk/res/android”

在列表视图中。