简体   繁体   中英

Displaying 'No Data' with ListView

I'm using a ListView, and it is not working properly. Please see my code.

<LinearLayout
    android:id="@+id/playerlist"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
        <ListView 
                android:id="@+id/plist"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" /> 
        <TextView
                android:id="@id/android:empty"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="NO DATA" />
</LinearLayout>

Well, It works well if the list is empty.

But as the list is short, You can see the 'NO DATA' below the ListView.

If you set the layout_height of the ListView to 'fill_parent', the 'NO DATA' can't appear.

Can anyone help me?

You must apply setEmptyView(View emptyView) to your listview.

Give your TextView an id, say emptyView ;

TextView emptyView = (TextView)findViewById(R.id.emptyView);
yourListView.setEmptyView(emptyView);

should do the trick.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM