0

I'm trying to show thumbnails of images from sdcard in a gridview. I'm using universal image loader and image loading is takes reasonable time.

My problem is: trying to get all paths for the thumbnails takes too much time and causes lag on the gridview scroll. If i try ro read all paths ahead of the loading images then it takes 10 seconds (500 images on S5). I see a lot of app already solved this problem and it seems i am making some fundemantal mistakes here, yet i couldn't find what it is.

PS: I got this code from an answer on stackoverflow and i think my problem is not related to code but it is related with my approach to the problem. Here is the code:

public static String getThumbnailPath(Activity activity, long imageId) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

    CursorLoader cursorLoader = new CursorLoader(activity, uri, proj, null, null, null);
    Cursor cursor = cursorLoader.loadInBackground();



    cursor.moveToFirst();

    String result="";
    cursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(activity.getContentResolver(), imageId,
            MediaStore.Images.Thumbnails.MINI_KIND, null);
    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();
        result = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA));
        cursor.close();
    }

    result = "file://" +  result;
    return result;
}
3
  • Use pagination? ie load only a few articles at a time. Not all of them. You can google how to do it
    – Darpan
    Nov 24, 2014 at 12:33
  • Please post relevant source code.
    – user468311
    Nov 24, 2014 at 12:34
  • I am loading only few of them when they are reqired to shown but then it causes lags when user scrolls the gridview.
    – user65721
    Nov 24, 2014 at 12:36

1 Answer 1

0

Have a look at smoothie by Lucas Rocha. It is a library project for fast scrolling listviews and gridviews. I use it in my app Playlist Manager. Easy to implement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.