listview设置数据为空时显示数据

来源:互联网 发布:练钢琴软件 编辑:程序博客网 时间:2024/04/28 03:46

数据为空的时候显示数据

android 系统在view里面预制了一个方法

帮助我们实现这个效果

就是 view.setEmptyView();

以下是代码实现过程 还有注意事项

//在listview初始化以后设置如下参数即可//设置 Paams.height 是因为默认就是warp 布局该了也一样//所以只能通过代码去设置他的高  这个可以定死值 //但是最好是 自动获得屏幕高度View emptyview = (FrameLayout) View.inflate(ac,R.layout.layout_emptyview,null);        emptyview.setVisibility(View.GONE);        ((ViewGroup)mLv.getParent()).addView(emptyview);        ViewGroup.LayoutParams layoutParams = emptyview.getLayoutParams();        layoutParams.height  =  500 ;        emptyview.setLayoutParams(layoutParams);        mLv.setEmptyView(emptyview);

//特别注意 代码不要这么写

//不要在 layout里面直接 include 或者 写 empty布局<LinearLayout    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:background="@color/white"    xmlns:android="http://schemas.android.com/apk/res/android">    <include layout="@layout/layout_title2"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        />    <com.hanjin.app.zhitou.views.ScrollView        android:layout_width="match_parent"        android:id="@+id/calluser_scrollview"        android:layout_weight="@integer/layout_weight_nine"        android:layout_height="0dp">        <include layout="@layout/layout_lv_emptyview"            />        <include layout="@layout/layout_listview" />    </com.hanjin.app.zhitou.views.ScrollView></LinearLayout>/***根据机型会出现 如下类似错误*Error inserting _name=com.vlife.huawei.wallpaper:main _pid=7972 *_is_sys=0 _is_uped=0**/

本篇博客结束
如果觉得对你有帮助

粉我把
关注更多我的blog.

技术交流群:

博客圈 493554215

这是一个热爱分享技术,拥有热烈学习氛围的群 ,
博主身为群内的一员感到骄傲
推荐还在路上的伙伴们

0 0