【发布时间】:2013-05-23 18:10:17
【问题描述】:
当列表为空时,我使用扩展 ListActivity 来显示空消息。 下面是我的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" >
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0">
</ListView>
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No Items! Please Add!"/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Add Item" />
</LinearLayout>
我的问题是按钮只能在列表中有项目时出现,但在列表为空时不能出现。列表为空时,按钮怎么出现?
【问题讨论】:
-
您可以动态检查列表中是否存在要显示的元素,如果没有,则将可见性设置为 GONE。