通过添加一个id为android:empty的TextView,当ListView里面没有data的时候,就会显示TextView的内容。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="对不起,没有数据显示"/>
</LinearLayout>

需要注意的是,ListView的id,使用的是"@id/android:list",即系统默认的id,而紧接其后的TextView,使用的id也是系统默认的,即"@id/android:empty"。

更多相关文章

  1. android shape的使用
  2. 《第一行代码——Android》
  3. ubuntu 使用android studio 查看android(android-5.1.0_r3)源码
  4. Android(安卓)shape使用
  5. Android(安卓)入门 和 环境搭建
  6. Android开发新手学习总结(一)——使用Android(安卓)Studio搭建An
  7. Android——init.rc脚本
  8. Android中SQLite数据库操作(1)——使用SQL语句操作SQLite数据库
  9. Android开发之5.0特性深入理解(一)

随机推荐

  1. android source code 备忘
  2. android 监听Home键和亮灭屏
  3. Android TextView控件文字添加下划线
  4. Linux | 安装与配置Android SDK
  5. android基于AndPermission的权限申请封装
  6. Android 中文API:如何安全的为APK进行签名
  7. Android实验九之天气预报
  8. picasso框架的使用
  9. android resouce list
  10. Android 获取缩略图,网络视频,或者本地视