Question

I am trying to make a listview which has a textview and an imageview for each row. In the imageview i am trying to load thumbnails using a custom adapter. My question is that if I have about 1000 thumbnails, is it a good idea to save images in res/drawable folder and directly load from there (as the images are really small about 2-4kb). Or is it a better option to download them from a web url and them load them into the listView. Can someone help me on finding out the wiser solution. Also later on its possible that i use more than 1000 thumbnails.

thanks

Was it helpful?

Solution

If you are keeping all the 1000 images in the res folder, the application size will increase by 2-4 Mb.

So, better go for downloading images from web server using lazy loading. Because, usually users won't scroll down to more that 100 items. So to show <100 images for 99% of the time, its useless to have all the 1000 images in the application res folder.

Check the highest voted answer here:

Lazy load of images in ListView

Thats what i am using in my application. Very happy with it.

OTHER TIPS

Sure, you could keep all your images in the drawable folder. That would be a faster and a cleaner solution, as long as you don't intend to add images later.

You save data charges, battery life and coding effort :)

1000 isn't such a large number, I would say, since your images are really that small. But, if it goes beyond that, it might be a problem.

I also don't think that you would need all the 1000 or 2000 images all the time, for every user. That way, you would probably be better off downloading the relevant images from some place, instead of packaging it with the app.

You should download the thumbs, no doubts about that. How you can optimise the code is by making a soft cache of all the views that are there in the Listview.

@Archie.bpgc answer is perfect. It will be better if you load image asynchronously from URL. It will be more better if you get part by part image list from server. that means first time it get 20 item from server after that it will get next 20 items from server.

To load image from server asynchronously you can use Picasso small library. Here is gradle

compile 'com.squareup.picasso:picasso:2.3.3'

here is your ImageView

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

Here is the simple java code

ImageView imageView = (ImageView) findViewById(R.id.imageView);

    Picasso.with(this)
            .load("YOUR_IMAGE_URL")
            .into(imageView);

That's it. For more information , visit here and if you have confusion about Picasso , the view this link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top