Android 处理空列表的方法(必看篇)
2019年11月02日
作者:佚名
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 处理空列表的方法(必看篇)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程小技巧。
以上是来客网为你收集整理的Android 处理空列表的方法(必看篇)全部内容,希望文章能够帮你解决Android 处理空列表的方法(必看篇)所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。