2012-07-10 101 views
1
崩潰

我從調試器收到此錯誤:設置內容的瀏覽在ListActivity

ERROR/AndroidRuntime(10540):了java.lang.RuntimeException:致 您的內容必須有一個ListView,其id屬性是 'android.R.id.list'

我的佈局文件如下:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#004D79" 
    > 
     <RelativeLayout android:id="@+id/relativeLayout1" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"> 
     <ListView 
      android:id="@+id/list" 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
     /> 
     <EditText 
      android:layout_alignParentLeft="true" 
      android:text="EditText" 
      android:layout_marginTop="10dp" 
      android:id="@+id/editText" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:layout_toLeftOf="@+id/skipButton"> 
     </EditText> 
     <Button android:text="Skip" 
     android:id="@+id/skipButton" 
     android:textSize="18dp" 
     android:layout_marginTop="10dp" 
     android:layout_alignParentRight="true" 
     android:layout_height="wrap_content" 
     android:layout_width="80dp"> 
     </Button> 
    </RelativeLayout> 
</LinearLayout> 

我在做什麼錯誤?

編輯:

所以我的列表視圖我仍然使用的ListView = getListView();

+1

如果你擴展ListActivity你需要給機器人:ID = 「@機器人:ID /列表」。 – 2012-07-10 16:22:33

回答

4

聲明ListView的ID爲:的

<ListView android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 

代替

<ListView 
      android:id="@+id/list" 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
     /> 
+1

所以對於我的列表視圖我仍然使用listView = getListView(); ? – user1417302 2012-07-10 16:21:18

+1

@ user1417302:是的 – ninetwozero 2012-07-10 16:26:43