Empty text view message when listview is empty

有些话、适合烂在心里 提交于 2019-12-13 21:20:01

问题


I have a ListView with an empty list catch in the XML and it works fine. How to toggle ListView Empty Text please ?

This is my XML code :

<?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"
android:orientation="vertical" >

<TextView
    android:id="@+id/empty"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/emptyList" />

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        /> 

</LinearLayout>

I'm not using a ListActivity. It s possible to do that please ?


回答1:


You just need to make use of setEmptyView(View v):

person_ListView.setEmptyView(root.findViewById(R.id.empty));

offtopic: ListActivity is using this method also, but with android.R.id.empty.



来源:https://stackoverflow.com/questions/19498322/empty-text-view-message-when-listview-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!