我有一个的ListView
。其背后的数据从因特网获取,在套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);
不幸的是,虽然这并隐藏视图,它留下的空间吧。即我结束了一个很大的空白空间,加载消息,曾经是。我如何去正确地躲在这个观点?
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
,你不能叫 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( )
在 setAdapter()
只要你之前调用这些方法之一至少一次的 。这是谷歌一个相当糟糕的设计决定的,所以我提出的问题 。与 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.