如何在 RecyclerView Header Decor 中设置侦听器? [英] How can I set a listener inside a RecyclerView Header Decor?

查看:30
本文介绍了如何在 RecyclerView Header Decor 中设置侦听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 RecyclerView 中使用了 这个库

I implemented sticky headers in my RecyclerView, using this library

我想在自定义标题中添加一个可点击的视图,但是当我在

I want to add a clickable view inside the custom header, but when I set the listener in the

public void onBindHeaderViewHolder(HeaderHolder viewholderHeader, int position)

它无视我,点击后面的项目(recyclerview列表的背景选择器).

It ignores me, and the item of behind is clicked (background selector of the recyclerview list).

onBindHeaderViewHolder 正在工作,因为我在那里有 setText.我想知道一种方法可以让 OnClickListener 持续存在并且视图接收它.(如果可能,不回收).

the onBindHeaderViewHolder is working, because of the setText I have in there. I want to know a way to do that the OnClickListener persists and the view receives it. (Without recycling if it is possible).

推荐答案

EDIT of 29/03/2016: 现在可以使用 ViewHolder 的相同侦听器点击粘性标题,不再使用 物品装饰.而是使用 FrameLayout.

EDIT of 29/03/2016: Sticky Headers are now clickable using same listeners of the ViewHolder, not using anymore ItemDecoration. A FrameLayout is instead used.

答案:我研究过header-decorsticky-headers-recyclerview 上,我的结论是,ItemDecoration 不应该是实现真正好的粘性标题的方式,因为我们所拥有的只是在顶部绘制的东西,不是视图(!),因此我们无法在其上附加任何侦听器我们不能与那个东西互动.

Answer: I've worked on header-decor and on sticky-headers-recyclerview and my conclusion is that, ItemDecoration should not be the way to implement a real good sticky headers, because what we have is just something drawn on the top and is not a view(!) so we cannot attach any listener on that thing and we cannot interact with that thing.

但是...我能够,在我的FlexibleAdapter 项目中, 拦截对 sticky 标题的点击,现在它已成为此功能的高级解决方案.

But... I was able, in my FlexibleAdapter project, to intercept the tap on the sticky header, now it is become an advanced solution for this functionality.

在此处查看我的评论:

另一个非常重要的注意事项:

我在上面提到的两个项目,大量使用循环for语句:他们在上面多次绘制,作为装饰"items (with onDrawOver),当前显示的所有标题.不仅如此,他们还将所有视图和对位置的引用放入缓存中没有回收(!).

The 2 projects, I mentioned on the top, make heavy use of cycle for statement: they draw, as a "decoration" many times on the top of the items (with onDrawOver), all the headers currently displayed. Not only, they put in a cache ALL the views and the reference to the positions without recycling(!) them.

你可以想象每次列表滚动每个像素时,内存增加多少,手机做了多少工作,电池消耗巨大......呵呵......我在新的东西中删除了所有这些东西StickyHeaderHelper.

You can imagine how much the memory increases and how much work the phone is making every time the list is scrolled of every pixel, with a huge battery consummation... Huh... I have removed all these things in the new StickyHeaderHelper.

这篇关于如何在 RecyclerView Header Decor 中设置侦听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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