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

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

问题描述

我使用这个库在我的RecyclerView中实现了粘性标题



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

 <$ c $中设置监听器时c> public void onBindHeaderViewHolder(HeaderHolder viewholderHeader,int position)

它忽略了我,被点击(recyclerview列表的背景选择器)。

onBindHeaderViewHolder正在工作,因为我在那里有setText。我想知道一种方法来实现OnClickListener持久化并且视图接收它。 (如果可能的话,不要回收)。

现在可以使用ViewHolder的相同侦听器来单击标题,而不再使用 ItemDecoration 。 A FrameLayout 被使用。



答案:我曾在 header-decor sticky-headers-recyclerview ,我的结论是,ItemDecoration 不应该是实现一个真正的好粘头的方式,因为我们只是在顶部绘制的东西,而不是视图(!),所以我们不能在该东西上附加任何侦听器,并且我们无法与该东西进行交互。



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



请在此处查看我的评论:





另一个非常重要的提示:



上面提到的两个项目使语句的 c 成为 ,作为项目顶部的多次装饰(使用 onDrawOver ),当前显示的所有标题。不仅如此,他们还将所有视图和对位置的引用放入缓存中,而无需循环使用(!)您可以想象如何内存增加了很多,手机每做一次像素滚动的时候手机的工作量就会大大增加,这是一个巨大的电池消耗......呃......我已经在新的 StickyHeaderHelper中删除了所有这些东西


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)

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

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: Sticky Headers are now clickable using same listeners of the ViewHolder, not using anymore ItemDecoration. A FrameLayout is instead used.

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.

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.

See my comments here:

Another very important note:

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.

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头部装饰中设置侦听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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