列表为空时 addHeaderView 不起作用 [英] addHeaderView does not work when the list is empty

查看:25
本文介绍了列表为空时 addHeaderView 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下布局(header.xml)在列表视图中添加标题,

I am using following layout(header.xml) to add header in a listview,

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/greetingContainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

<TextView
    android:id="@+id/categoryTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="header view"
    android:textColor="#FFFFFF"
    android:textSize="15sp" />

</LinearLayout>

另一方面,我正在使用,

and on the other side, i am using,

View header = (View) getLayoutInflater().inflate(R.layout.header,null);
getListView().addHeaderView(header);

当列表为空时它不起作用,保持不可见..

when the list is empty it's not working, stays invisible..

我的问题可能与这个重复,但无法理解,
请帮忙!

my question may be the duplicate of this, but unable to understand,
please help!

推荐答案

简单的解决方案,您需要做的就是始终为您的 listview 设置一个适配器,即使您没有要显示的任何数据.

Simple solution, all you need to do is that you should ALWAYS set an adapter for your listview, even when you do not have any data to show.

这篇关于列表为空时 addHeaderView 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆