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

查看:200
本文介绍了当列表为空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>

和在另一边,我使用,

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

在列表为空它不工作,保持隐形。

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

我的问题可能是重复的<一个href=\"http://stackoverflow.com/questions/4988011/android-addheaderview-disappears-when-no-items-in-listview\">this,但无法理解,结果
请大家帮忙!

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

推荐答案

简单的解决方案,所有你需要做的是,你必须总是设置一个适配器为你的列表视图 。你必须设置甚至适配器时你仍然有数据显示。

Simple solution, all you need to do is that you have to always set an adapter for your listview. You have to set an Adapter even when you still have to data to show.

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

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