android 开发技巧(13)--处理空列表
2016-03-03 11:02
453 查看
android中ListView 用来展示数据,如果列表为空的状态,可以通过setEmpty(View)方法设置为空时显示的内容。
布局xml
代码:
布局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/empty_view" /> </FrameLayout>
代码:
public class Hack24Activity extends Activity { private ListView mListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hack24); mListView = (ListView) findViewById(R.id.my_list_view); mListView.setEmptyView(findViewById(R.id.empty_view)); } }
相关文章推荐
- 如何停止Android Monkey脚本
- Android中Window添加View的底层原理
- android:exported 属性详解
- Animation特效——Tween Animation
- Android中的观察者模式
- Android SQLite (一) 数据库简介
- Android滑动锁屏
- Android时间间隔 SystemClock.uptimeMillis 和 System.currentTimeMillis
- Android Studio常用快捷键
- Android之取消ViewPage+Fragment的预加载
- android从零单排之Environment
- android 报错:invalid resource directory name bin/res/crunch
- Android--播放Gif的取巧办法
- android:largeHeap
- MVC模式在android 中的运用
- android中设置控件获得焦点 (转)
- Android开发规范
- 设计模式及在Android中的应用
- 重要的Android术语
- ANDROID自定义视图——onMeasure,MeasureSpec源码 流程 思路详解