Android的addHeaderView消失在ListView中时,没有任何项目 [英] Android addHeaderView disappears when no items in ListView

查看:162
本文介绍了Android的addHeaderView消失在ListView中时,没有任何项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 addHeaderView 来一个视图项添加到的ListView 的顶部。我也有一个的TextView 来显示一个消息,说有列表中没有的项目。

I am using addHeaderView to add a view item to the top of a ListView. I also have a TextView to display a message saying there are no items in the list.

下面的布局:

<ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>          

<TextView
    android:id="@android:id/empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="@string/list_empty"
    android:gravity="center"
    android:textAppearance="?android:attr/textAppearanceMedium" />

和Java code:

And the Java code:

final ListView listView = getListView();
final View view = getLayoutInflater().inflate(R.layout.list_item_add,
            listView, false);
listView.addHeaderView(view, null, true);

当有在ListView项则头示出,但如果我删除列表中的所有项目(除头部视图),则报头视图中消失。

When there are items in the ListView then the header is shown but if I delete all items in the list (except the header view) then the header view disappears.

我想的标题视图要在列表视图中是否有列表或不可见的项目。

I would like the header view to be visible in the list view whether there are items in the list or not.

谢谢

推荐答案

删除 @android:ID /空从布局来看,或覆盖/继承您的适配器从返回假的isEmpty()

Remove the @android:id/empty view from your layout, or override/subclass your adapter to return false from isEmpty()

这篇关于Android的addHeaderView消失在ListView中时,没有任何项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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