当我们使用listview加载数据时,会出现几种状况!一种是有数据的情况。一种是没有数据的情况。
没有数据的话listview就是显示空空的什么都没有!这里的setEmptyView()就派上用处了!你肯定要给用户一些提示信息!如何提示呢!嘿嘿下面例子看。
java代码:
效果如下:
嗯完成了!这里记录下!
没有数据的话listview就是显示空空的什么都没有!这里的setEmptyView()就派上用处了!你肯定要给用户一些提示信息!如何提示呢!嘿嘿下面例子看。
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/layoutTitlebar">
<ListView
android:id="@+id/listViewFriends"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/friendBGColor"
android:cacheColorHint="#00000000">
</ListView>
<TextView
android:id="@+id/empty"
android:text="@string/strNoRecordsFound"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@android:style/TextAppearance.Large"
android:gravity="center">
</TextView>
</LinearLayout>
java代码:
ListView listViewFriends = (ListView) findViewById(R.id.listViewFriends);
// set your adapter here
// set your click listener here
// or whatever else
listViewFriends.setEmptyView(findViewById(R.id.empty));
效果如下:
![](http://bbs.51cto.com/images/default/attachimg.gif)
嗯完成了!这里记录下!