ListView 数据为空的时候提示怎么写?
2016-03-14 14:25
507 查看
ListView及其他继承自AdapterView的类都有一个简便的处理这种情况的方法:setEmptyView(View)。
当ListView的Adapter为空或者Adapter的isEmpty()方法返回true的时候,它将会把设置的emptyview绘制出来。
当ListView的Adapter为空或者Adapter的isEmpty()方法返回true的时候,它将会把设置的emptyview绘制出来。
举个栗子,假设我们需要创建一个应用来管理我们的待办事项,我们的主页面将会是一个用来展示这些待办事项的ListView。 而当我们第一次载入进这个应用时,待办事项必然为空。此时我们就可以利用一个图片或者一段描述性的话来表达“无待办事项”。 看看XML布局文件:
<FrameLayout 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/my_list_view" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <ImageView android:id="@+id/empty_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/mrectangle" /> </FrameLayout>
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.my_list_view); listView.setEmptyView((findViewById (R.id.empty_view))); }
相关文章推荐
- 程序员的鄙视链
- JS正则表达式匹配<div><style>标签
- python 多线程就这么简单
- Android DialogFragment(1)
- 晓月_【游戏参考】九阴真经
- iOS-UIWebView
- CentOS7.1 KVM虚拟化之虚拟机克隆(4)
- Java中BIO,NIO,AIO的理解
- PHP魔术方法
- 原 IDEA Properties中文unicode转码问题
- MultipartFile
- 阿里架构之旅(四)——zookeeper的原理
- centos7安装zabbix(服务端)
- 如何反编译APK修改成自己想要的并打包运行
- python实例属性和类属性精讲
- postgres 备份所有数据库并还原
- 【Junit】JUnit-4.12使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误
- 【转载】「能写代码」是愚公移山,「会写代码」是女娲补天
- C指针解析 右左法则----复杂指针解析
- lua-table