isRecyclable decremented below 0: unmatched pair of setIsRecyable() calls

限于喜欢 提交于 2019-12-24 13:16:49

问题


I have created a RecyclerView with a very similar design to the one mentioned

here

and even used the excellent self-supplied solution in my implementation. Basically I have a RecyclerView that expands upon click to show an extra layout component for that entry.

That worked fine however once the view was expanded it sometimes got recycled and when scrolling to new views they would sometimes appear on screen in an expanded state which isn't what I was after. To resolve this I followed the advice from

this post

and set

holder.setIsRecyclable(false);

when clicked. This also seemed to work fine.

My only issue is that I now get the following error in my logs when the app is running and multiple views are getting clicked/scrolled/expanded/recycled.

isRecyclable decremented below 0: unmatched pair of setIsRecyable() calls

As far as I can tell I have a matching call to set the view back to recyclable, so can anyone shed some more info on what is causing the above error and what I need to do to resolve it? Full snippet of offending code below, this is in my onClickListener.

if (!isViewExpanded) {
    holder.setIsRecyclable(false);
    llCompInfo.setVisibility(View.VISIBLE);
    llCompInfo.setEnabled(true);
    isViewExpanded = true;
    scores.get(getAdapterPosition()).setShowCompInfo(true);
} else {
    holder.setIsRecyclable(true);
    llCompInfo.setEnabled(false);
    isViewExpanded = false;
    scores.get(getAdapterPosition()).setShowCompInfo(false);
}

回答1:


Keep "expanded" state in your items (adapter) and when onBind is called, use that information. You should not be messing w/ isRecycleable unless you are implementing some custom animations outside the ItemAnimator.



来源:https://stackoverflow.com/questions/31065481/isrecyclable-decremented-below-0-unmatched-pair-of-setisrecyable-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!