Search code examples
javaandroidxmllayoutscreen-size

ListView not showing items on a smaller screen


I had an emulator with a larger screen and it all works well. ListView shows everything perfectly normal so its not in the java code. I have tried testing it now on a 3.2 screen and ListView doesn't show anything. I tried with a smaller screen (3.2) emulator and it also didn't show anything so I guess this has something to do with they layout.

My listview.xml layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="150dp" >

    </ListView>

</LinearLayout>

row xml file :

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/text1"
        android:layout_width="match_parent"        
        android:gravity="center"
        android:layout_height="30dp" />

</LinearLayout>

Solution

  • You should never set android:layout_width and android:layout_height to wrap_content for ListView.