在ListView中隐藏页脚 [英] Hiding footer in ListView

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

问题描述

在我的活动负载,我吹,我使用的页脚布局文件。我将其附加到ListView(addFooterView),然后设置其知名度View.GONE。我保持对它的引用,当我希望用户看到它,我设置了能见度View.VISIBLE。

When my Activity loads, I inflate a layout file that I use for a footer. I attach it to the ListView (addFooterView) and then set its visibility to View.GONE. I maintain a reference to it, and when I want the user to see it, I set the visibility to View.VISIBLE.

在大多数情况下,这个伟大的工程。然而,页脚似乎仍然占用空间。如果用户使用滚轮/垫,页脚是占用的区域被突出显示。我想擦亮这更使页脚完全消失;最理想的情况从ListView中分离了。

For the most part, this works great. However, the footer seems to still take up space. If the user uses the scroll wheel/pad, the area the footer is taking up gets highlighted. I'd like to polish this more so the footer is completely gone; ideally without detaching it from the ListView.

这可能吗?或者我会简单地切换其知名度有设置警戒/解除警戒的脚呢?

Is this possible? Or am I going to have to set/unset the foot instead of simply toggling its visibility?

推荐答案

您可以使用 listView.removeFooterView(视图)。要做到这一点,最简单的方法是创建一个实例变量来保存你的膨胀页脚视图(所以你只夸大它在的onCreate())。然后,只需拨打 listView.addFooterView(instanceFooter) listView.removeFooterView(instanceFooter)需要。

You can use listView.removeFooterView(view). The easiest way to do this is to create an instance variable to hold your inflated footer view (so you only inflate it in onCreate() ). Then just call listView.addFooterView(instanceFooter) and listView.removeFooterView(instanceFooter) as needed.

编辑: 下面是我在做什么来得到这个工作:

Here's what I'm doing to get this to work:

  1. 在膨胀页脚布局(收费)的onCreate
  2. onResume:如果适配器没有实例,调用 addFooterView()然后初始化适配器(保持一个实例参考吧)和叫 setAdapter()。这将使的ListView prepped
  3. onResume:更新与数据适配器(我有我在一个单独的类数据),并调用 notifyDatasetChanged()
  4. 呼叫 removeFooterView()(它会隐藏它,如果它被显示,什么也不做,否则)
  5. 呼叫 addFooterView()如果页脚需要显示
  1. inflate footer layout(s) in onCreate
  2. onResume: IF the adapter has not been instantiated, call addFooterView() THEN initialize your adapter (keep an instance reference to it) and call setAdapter(). This will leave the ListView "prepped"
  3. onResume: update the adapter with the data (I have my data in a separate class) and call notifyDatasetChanged()
  4. Call removeFooterView() (it will hide it if it's being displayed and do nothing otherwise)
  5. Call addFooterView() if the footer needs to be displayed

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

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