Tutorial :Why won't my listview display?


I am trying to show a list of files using an ArrayAdapter into a ListView. As best as I can tell, the following should work but it is just leaving the ListView empty. I am not using a ListActivity.


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));  


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


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

Am I missing something obvious?



Have you checked hierarchyviewer to see what the measured size of your list is, how many children it has, and their sizes?

You're telling the ListView that its height should be wrap_content - this is meaningless for a ListView since its content can be arbitrarily large. You're also telling the list items to be fill_parent in height - this is meaningless for a container that can scroll, since the parent effectively has infinite height to fill.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »