我ListFragment
使用以下自定义布局创建了一个,它添加了一个TextView
以在列表为空时显示一条消息:
<?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="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/vsl_empty"
android:gravity="center"
android:layout_gravity="center"
android:textColor="#8C8C8C" />
</LinearLayout>
使用派生自 的自定义适配器加载数据CursorAdapter
。当数据库中有数据时,列表会非常简短地显示空列表消息,直到加载数据,此时列表被填充。
如何防止空列表消息因为列表尚未填充而短暂出现?
更新
我想强调的是,我使用的ListFragment
a 布局包含ListView
带有特殊 idandroid:list
的 a 和TextView
带有特殊 id的 a ,如此处android:empty
所述。
设置android:visibility="invisible"
不影响可见性。我怀疑这是因为它在内部设置为可见。