2011-10-24 35 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」

在列表視圖