rahulxxarora rahulxxarora - 29 days ago 8x
Android Question

How to remove lagging in RecyclerView showing captured images from the camera?

I am showing images captured from camera on cards using RecyclerView. I don't know why the app lags whenever I scroll down the screen. I am also using Picasso to load images async. Please help. Below is the code :

Check the onBindViewHolder function

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class DiaryAdapter extends RecyclerView.Adapter<DiaryAdapter.ViewHolder>{

List <DiaryInfo> mItems;

public DiaryAdapter() {
mItems = new ArrayList <DiaryInfo> ();
mItems = MainActivity.diaryinfo;

public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.content_main, viewGroup, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;

public void onBindViewHolder(ViewHolder viewHolder, int i) {
DiaryInfo info = mItems.get(i);

String data = info.getThumbnail();

String path=""; // Final path of the thumbnail

final SQLiteDatabase mydatabase = (MainActivity.mContext).openOrCreateDatabase("remember", android.content.Context.MODE_PRIVATE, null);

// While changing database information here change at Itemadd's done button listener also!
mydatabase.execSQL("CREATE TABLE IF NOT EXISTS memories_pics(id VARCHAR PRIMARY KEY, path VARCHAR)");

Cursor cursor = mydatabase.rawQuery("SELECT * FROM memories_pics WHERE id=\'" + data + "\' LIMIT 1", null);
if (cursor.moveToFirst()) {
while (cursor.isAfterLast() == false) {
path = cursor.getString(cursor

//Bitmap bmp = BitmapFactory.decodeFile(String.valueOf(path.split("=")[0]));
File file = new File(String.valueOf(path.split("=")[0]));

public int getItemCount() {
return mItems.size();

public Object getItem(int pos) { return mItems.get(pos); }

class ViewHolder extends RecyclerView.ViewHolder {

public ImageView imgThumbnail;
public TextView date, desc;

public ViewHolder(View itemView) {
imgThumbnail = (ImageView) itemView.findViewById(R.id.thumbnail);
date = (TextView)itemView.findViewById(R.id.date);
desc = (TextView)itemView.findViewById(R.id.description);



Try using