RecyclerView items duplicate and constantly changing

后端 未结 8 2234
遥遥无期
遥遥无期 2020-12-13 04:14

What\'s Happening:

The list (RecyclerView) is mixing up the data when I scroll.

I.E when I scr

相关标签:
8条回答
  • 2020-12-13 05:15

    use holder.setIsRecyclable(false); in onBindViewHolder of your adapter class

    0 讨论(0)
  • 2020-12-13 05:18

    The problem is the CardView and TextView objects are declared static inside the FeedViewHolder. That means that all the calls trying to set the title in the onBindViewHolder method hit the latest inflated View.

    The fix is to remove the static from cv, title, pubDate, description, then implement some non static setters like:

    public void setTitle(String s) {
        title.setText(s);
    }
    

    To be called in the onBindViewHolder method:

    @Override
    public void onBindViewHolder(RVAdapter.FeedViewHolder holder, int position) {
        holder.setTitle(items.get(position).getTitle());
        //...
    }
    
    0 讨论(0)
提交回复
热议问题