I am trying to load images from Internal storage of phone in a GridView. GridView is in a fragment. I have a class that stores the files paths to all images. I initialize the class's data once so that I don't have to it again and again. And then I set the adapter to GridView using that class.
This is the function of my data class.
public static void initialize(Cursor cursor) {
int count = cursor.getCount();
allPaths = new String[count];
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
allPaths[i] = cursor.getString(dataColumnIndex);
}
cursor.close();
}
This is the adapter of my Grid:
public View getView(int position, View convertView, ViewGroup parent) {
ImageView mImageView;
if (convertView == null) {
mImageView = new ImageView(mContext);
mImageView.setLayoutParams(new GridView.LayoutParams(250, 250));
mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
} else {
mImageView = (ImageView) convertView;
}
File f = new File(AllScreenshots.get(position));
Picasso.get().load(f).into(mImageView);
return mImageView;
}
The loading of images, scrolling of grid view and app becomes so slow. How can I make the loading, scrolling and app smooth and fast again?