2010-07-20 182 views
0

我想顯示一個使用ArrayAdapter到ListView的文件列表。盡我所知,以下應該可以工作,但它只是將ListView留空。我沒有使用ListActivity。爲什麼我的列表視圖不顯示?

的Java

setContentView(R.layout.files); 
findViewById(R.id.folder_use).setOnClickListener(this); 
ListView view = (ListView)findViewById(R.id.files); 
File[] files = Environment.getExternalStorageDirectory().listFiles(); 
Log.d(TAG, files.toString()); 
view.setAdapter(new ArrayAdapter<File>(this, R.layout.file_row, files)); 

layout.files

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content"> 

    <TextView android:id="@+id/local_instructions" android:text="@string/local_instructions" 
     android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" /> 

    <ListView android:id="@+id/files" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_below="@id/local_instructions" 
     android:background="#ffffff" /> 

    <Button android:id="@+id/folder_use" android:text="@string/folder_use" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_alignParentBottom="true" /> 
</RelativeLayout> 

layout.file_row

<?xml version="1.0" encoding="utf-8"?> 

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

我失去了一些東西明顯?

感謝

回答

1

你檢查hierarchyviewer,看看你的列表的度量大小,有多少孩子都有,只是尺寸不同?

你在告訴ListView它的高度應該是wrap_content - 這對於ListView來說是沒有意義的,因爲它的內容可以是任意大的。您還會告訴列表項目的高度爲fill_parent - 這對於可以滾動的容器來說是沒有意義的,因爲父項實際上具有無限高度來填充。

相關問題