user1591668
user1591668

Reputation: 2883

Android RecyclerVew Adapter slow performance

I am having performance issues with my recyclerview and I have read that the onBindViewHolder section of the RecyclerView.Adapter could be a cause for it. The main issue that I am having is just slow scrolling and sometimes it becomes unresponsive . This is my onBindViewHolder

 @Override
public void onBindViewHolder(ArtistViewHolder holder, int position) {
    final Artist artist = artists.get(position);

    holder.getBinding().artistImage.setImageBitmap(null);
    try {
        holder.setImage(artist, (int) DimensionUtil.convertDpToPixel(context, 120), (int) DimensionUtil.convertDpToPixel(context, 120));
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (position == artists.size() - 1) {

        endOfListListener.EndOfListReached();
    }
    holder.getBinding().setArtistClickListener(listener);
    holder.getBinding().setArtist(artist);
    holder.getBinding().setPosition(position);
    holder.getBinding().executePendingBindings();

}

is there anything in there that could be moved elsewhere to improve scrolling performance ? I do know that every item in onBindViewHolder is frequently accessed as your scrolling down the list .

Upvotes: 0

Views: 2208

Answers (1)

Pawneshwer Gupta
Pawneshwer Gupta

Reputation: 2342

This is because you are loading images (large images) on recyclerview. And onbindviewholder will attach images eveytime when u scroll the recyclerview.

Upvotes: 3

Related Questions