0

I have 8 items in my RecyclerView which contains an image and a title. The performance is extremely laggy.

I load images using Picasso. The images are not even high resolution to cause a lag.

Here is my adapter:

public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.CategoryViewHolder> {

private Context context;
private List<Category> categories;

class CategoryViewHolder extends RecyclerView.ViewHolder {
    TextView categoryTitle;
    ImageView categoryImage;

    CategoryViewHolder(View view) {
        super(view);
        categoryTitle = (TextView) view.findViewById(R.id.category_title);
        categoryImage = (ImageView) view.findViewById(R.id.category_thumbnail);
    }
}

public CategoryAdapter(Context context, List<Category> categories) {
    this.context = context;
    this.categories = categories;
}

@Override
public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.category_item, parent, false);
    return new CategoryAdapter.CategoryViewHolder(itemView);
}

@Override
public void onBindViewHolder(final CategoryViewHolder holder, int position) {
    Category category = categories.get(position);
    holder.categoryTitle.setText(category.getCategoryTitle());
    Picasso.with(context)
            .load(category.getCategoryImage())
            .into(holder.categoryImage);
}

@Override
public int getItemCount() {
    return categories.size();
}
}
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64
RandomyzeEverything
  • 764
  • 3
  • 7
  • 21

3 Answers3

1

Have you set any background image to your activity. if yes than check background image size.may be it is too big. that can make it laggy.

DB377
  • 403
  • 4
  • 11
0

One way is to call the method Asynchronously when obtaining images from picasso. Please check the following link from more info How to asynchronously call a method in Java

Community
  • 1
  • 1
0

I'm facing same issue this worked for me, after initialize recyclerview add below line

recyclerView.setNestedScrollingEnabled(false);
Omkar
  • 3,040
  • 1
  • 22
  • 42