如何将Recyclerview物品保持在同一位置? [英] How to keep Recyclerview items at same position?

查看:134
本文介绍了如何将Recyclerview物品保持在同一位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题.我从Fragment类中填充一个Recyclerview.到目前为止,一切正常.但是,当我测试我的应用程序并在填充的回收站列表中上下滚动时,每个项目的内容也发生变化,它们将被回收...

I have the following issue. I populate a Recyclerview from my Fragment class. So far everything works out. However when I test my app and scroll up and down the populated recycler list the contents of each item change a.k.a. they get recycled...

滚动后如何保存每个项目的位置并将其内容恢复到同一位置?

How can I save each item's position and restore its content to the same position after scrolling?

有什么建议吗?

推荐答案

好问题,这是您的答案 holder.setIsRecyclable(false).

Good Question, this is your answer holder.setIsRecyclable(false).

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.product_recycle_buyer_list_item, parent, false);
    MyViewHolder holder = new MyViewHolder(view);

    holder.setIsRecyclable(false);

    return holder;
}

这篇关于如何将Recyclerview物品保持在同一位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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