android 开发技巧(13)--处理空列表

来源:互联网 发布:java窗口程序实例 编辑:程序博客网 时间:2024/05/22 10:53

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));    }}
0 0
原创粉丝点击