The situation is the following, there is a RecyclerView load data from sqlite 80 records, item looks like this, on the left is an image, in the center is the text. The problem is that during fast scrolling, the recycler begins to lag tightly. Initially I thought that the problem is in setImageResource() , since I read somewhere that this method is best used for lazy operations. Replaced it with setImageDrawable(drawable) , rendered this piece of code in the Handler
int imageId = context.getResources().getIdentifier(item.getImageName(), "drawable", context.getPackageName()); Drawable drawable = context.getDrawable(imageId); holder.imageView.setImageDrawable(drawable); The situation has not changed. The images are in drawable format VectorDrawable and with a size of 45dp x 45dp. How to optimize recycler , that would not lag with fast scrolling?
UPDATE:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private Context context; private List<Item> dataList; public MyAdapter(Context context, List<Item> dataList) { this.context = context; this.dataList = dataList; } public class MyAdapter.ViewHolder extends RecyclerView.ViewHolder{ public TextView mTextView; public ImageView imageView; public ViewHolder(View view) { super(view); mTextView = view.findViewById(R.id.name_item); imageView = view.findViewById(R.id.image_item); } } @Override public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.my_item, parent, false); MyAdapter.ViewHoldervh = MyAdapter.ViewHolder(itemView); return vh; } @Override public void onBindViewHolder(final MyAdapter.ViewHolder holder, final int position) { final Item item = dataList.get(position); holder.mTextView.setText(item.getName()); int imageId = context.getResources().getIdentifier(item.getimageId(), "drawable", context.getPackageName()); Drawable drawable = context.getDrawableimageId holder.imageView.setImageDrawable(drawable); } @Override public int getItemCount() { return dataList.size(); } }