在 ListView 中隐藏页脚视图? [英] Hide footer view in ListView?

查看:29
本文介绍了在 ListView 中隐藏页脚视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListView.它背后的数据是从 Internet 获取的,每当用户一直滚动到底部时,就会以 10-30 项为一组.为了表明它正在加载更多项目,我使用了 addFooterView() 添加一个简单的视图,显示正在加载..."消息和一个微调器.现在,当我用完数据(没有更多数据可获取)时,我想隐藏该消息.我试着做:

I have a ListView. The data behind it is fetched from the Internet, in sets of 10-30 items whenever the user scrolls all the way to the bottom. In order to indicate that it is loading more items, I used addFooterView() to add a simple view that displays a "Loading..." message and a spinner. Now, when I'm out of data (no more data to fetch), I want to hide that message. I tried to do:

loadingView.setVisibility(View.GONE);

不幸的是,虽然这确实隐藏了视图,但它为它留下了空间.IE.我最终得到了一个很大的空白区域,加载"消息曾经是这样的.如何正确隐藏此视图?

Unfortunately, while that does hide the view, it leaves space for it. I.e. I end up with a big blank space where the "Loading" message used to be. How can I go about properly hiding this view?

我不能使用 removeFooterView() 因为我可能需要再次显示它,在这种情况下我不能再次调用 addFooterView() 因为适配器有ListView上已经设置好了,设置了adapter后就不能调用addHeaderView()/addFooterView()了.

I can't use removeFooterView() because I may need to show it again, in which case I can't call addFooterView() again because an adapter has already been set on the ListView, and you can't call addHeaderView() / addFooterView() after setting an adapter.

推荐答案

似乎允许调用 addHeaderView()/addFooterView() after setAdapter() 只要您之前至少调用过其中一种方法.这是 Google 的一个相当糟糕的设计决定,所以我提交了一个问题.将它与 removeFooterView() 结合起来,你就有了我的解决方案.

It seems that you are allowed to call addHeaderView() / addFooterView() after setAdapter() as long as you call one of those methods at least once before. That is a rather poor design decision from Google, so I filed an issue. Combine this with removeFooterView() and you have my solution.

+1 对于我得到的其他两个答案,它们是有效的(可以说是更正确的)解决方案.然而,我的答案是最简单的,我喜欢简单,所以我会将我自己的答案标记为已接受.

+1 for the other two answers I got, they're valid (and arguably more correct) solutions. Mine, however, is the simplest, and I like simplicity, so I'll mark my own answer as accepted.

这篇关于在 ListView 中隐藏页脚视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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