2011-01-11 68 views
1

我有一個簡單的ListActivity,它使用ListAdapter,我想自定義ListView。這裏是我的onCreate,在這裏我指定要使用視圖,而不是使用()由setListAdapter生成默認的ListView:通過XML自定義ListView問題

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    // set the listview, empty listview 
    setContentView(R.layout.main); 
    getListView().setEmptyView(findViewById(android.R.id.empty)); 

    // set the list properties 
    getListView().setOnCreateContextMenuListener(this); 

    . 
    . 
    . 
    <code snipped> 
    . 
    . 
    . 

    setListAdapter(adapter); 
} 

你可以看到,我設置emptyView爲好。下面是XML文件的main.xml:

<?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"> 

    <ListView 
    android:id="@id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fadingEdge="vertical" 
     android:dividerHeight="5dp" /> 
    <TextView 
    android:id="@android:id/empty" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:singleLine="false" 
     android:text="@string/message_empty_list" /> 
</LinearLayout> 

我的問題是,ListView控件,而正確應用dividerHeight,被忽略了:fadingEdge指令時,它在XML;但是,如果我設置fadingEdge編程,它的工作原理,即:

getListView().setVerticalFadingEdgeEnabled(true); 

任何想法,爲什麼ListView的將是專門無視fadingEdge?我是否做了不正確的事情,可能導致這種行爲?

謝謝!

回答

0
android:id="@id/android:list" 

應該

android:id="@iandroid:id/list" 

我甚至不知道爲什麼,編譯。

這就是你應該如何使用自定義xml的listactivities。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
     <ListView 
      android:id="@android:id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
     <TextView 
      android:id="@android:id/empty" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="No data found" 
      android:gravity="center" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
</FrameLayout> 
+0

我本來它的Android版本:ID /列表,我希望它是,但它並沒有那麼工作要麼...所以我做了搜索,並在頁面上這裏建議其更改爲來到@ id/android:list ...當然現在我找不到那個頁面。無論如何,簡短的回答是它仍然無法改變android:id – 2011-01-11 04:18:40