Android 处理空列表的方法(必看篇)
更新时间:2017年04月18日 10:13:33 投稿:jingxian
下面小编就为大家带来一篇Android 处理空列表的方法(必看篇)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
android中ListView 用来展示数据,如果列表为空的状态,可以通过setEmpty(View)方法设置为空时显示的内容。

布局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 处理空列表的方法(必看篇)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
自定义RadioButton和ViewPager实现TabHost带滑动的页卡效果
在工作中又很多需求都不是android系统自带的控件可以达到效果的所以这个时候就要自定义控件来达到效果:使用自定义RadioButton和ViewPager实现TabHost带滑动的页卡效果2013-01-01
Android中ExpandableListView使用示例详解
这篇文章主要为大家详细介绍了Android中ExpandableListView使用示例,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-10-10


最新评论