本文介绍了当listview为空时,文本查看消息为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个ListView,其中XML中有一个空列表捕获,它工作正常.请问如何切换ListView空文本?
I have a ListView with an empty list catch in the XML and it works fine. How to toggle ListView Empty Text please ?
这是我的XML代码:
<?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>
我没有使用ListActivity.可以这样做吗?
I'm not using a ListActivity. It s possible to do that please ?
推荐答案
您只需要使用 setEmptyView(View v)
:
You just need to make use of setEmptyView(View v)
:
person_ListView.setEmptyView(root.findViewById(R.id.empty));
offtopic : ListActivity
也在使用此方法,但使用的是 android.R.id.empty
.
offtopic: ListActivity
is using this method also, but with android.R.id.empty
.
这篇关于当listview为空时,文本查看消息为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!