如何动态添加页脚视图
我创建了一个 ListView
并使用 addHeaderView
添加了标头,然后在我的 ListActivity
中调用了 setListAdapter
。知道如何在调用 setListAdapter
后动态地 addFooterView
吗?
回答: 我将页眉视图和页脚视图(实际上是按钮)添加到列表视图中, 但是我使用wrap_content高度将它们包装到FrameLayout中,然后当我不需要显示标题按钮时,我只需setVisibility(View.GONE)并且FrameLayout包装到0高度并且视觉上它不可见(相同的效果就像我会调用removeHeaderView),如果我需要再次显示它,我设置Visibilty(View.VISIBLE)并显示它(与addHeaderView效果相同 - 这在调用后当然是不可能的设置列表适配器)
此处讨论: 在 ListView 中隐藏页脚视图吗?
I have created a ListView
and added header with addHeaderView
, then I called setListAdapter
in my ListActivity
. Any idea how can I dynamically addFooterView
after I called setListAdapter
?
ANSWER:
I added both header view and footer view (actually buttons) into my list view,
but both of them I wrapped into a FrameLayout using wrap_content height, then when I do not need to be the header button to be shown I just setVisibility(View.GONE) and FrameLayout wraps to 0 height and vissualy it is not visible (same effect as if I would call removeHeaderView), and if I need to show it again I setVisibilty(View.VISIBLE) and it is shown (same effect as addHeaderView - which is of course not possible after calling setting list adapter)
Discussed here:
Hide footer view in ListView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你必须这样做
You Have to do like this