您的位置:首页 > 移动开发 > Android开发

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

2016-03-03 11:02 453 查看
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));

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: