我需要帮助。
我有一个 Listview.setListAdapter(arrayAdapter) 和数组适配器有一个 arrayList。
If my arrayList is empty it shows loading images, it is normal, but how can i show a message if my arrayList is empty?
Thanks in advance.
常见的方法是在列表视图之后设置一个空的文本视图(@android:id/empty):
<?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="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:dividerHeight="1dp" >
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/empty_list" />
</LinearLayout>
然后将空视图设置为列表视图:
ListView lv = (ListView)findViewById(android.R.id.list);
TextView emptyText = (TextView)findViewById(android.R.id.empty);
lv.setEmptyView(emptyText);
这应该在列表中的项目存在时显示它们,并且在不存在时显示文本视图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)