Activity->2个Fragment
未购买页面,服务器端暂时没有数据,但是显示空白页面,显然不好看,用户体验也不好,所以当没有数据时候显示默认提示页面
xml布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout style="@style/resum_base_linerlayout" >
<TextView
style="@style/resum_base_title"
android:text="按时间顺序" />
<View style="@style/resum_base_view" />
<TextView
android:id="@+id/releaseTime"
android:layout_marginRight="30dip"
style="@style/resum_base_desc"
android:layout_weight="1"
android:text="最近三个月"
android:drawableRight="@drawable/pull_down"></TextView>
</LinearLayout>
<com.runsheng.zyzp4a.view.RefreshListView
android:id="@+id/tPurchase_lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:dividerHeight="0dip" >
</com.runsheng.zyzp4a.view.RefreshListView>
<LinearLayout
android:id="@+id/myText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:src="@drawable/aa"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="40dp"
android:gravity="center"
android:textSize="25sp"
android:text="SORRY,本页面没有内容!" />
</LinearLayout>
</LinearLayout>
布局很简单,com.runsheng.zyzp4a.view.RefreshListView就是一个Listview,
在fragment或activity中加上
private RefreshListView lv;
.........
lv=(RefreshListView) view.findViewById(R.id.tPurchase_lv);
lv.setEmptyView(view.findViewById(R.id.myText));
RefreshListView==Listview
只需要调用在代码中调用setEmptyView(View emptyView)设置ListView为空时显示这个默认布局即可。
因为setEmptyView(View emptyView)这个方法是属于AdapterView这个类的,所以除了ListView之外,其他的子类,如GridView,Spinner等,应该也可以用这个方法来设置Adapter数据为空时显示另一个View。