1

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

Swati Rawat
  • 1,729
  • 1
  • 19
  • 34
  • List view loading image You can try lazy adapter.. Here's the link it may help you http://thinkandroid.wordpress.com/2012/06/13/lazy-loading-images-from-urls-to-listviews/ – Janmejoy Jan 10 '13 at 06:15

4 Answers4

2

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.

Community
  • 1
  • 1
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • @user370305, Yes Google play allows upto 50mb but what about the users? Everyone prefers low memory apps right? – Archie.bpgc Jan 10 '13 at 05:34
  • No, my point is when you have an option to deliver it in 5mb and 9 mb size. Its recommended to go with 5mb. Like i said, most of the users will see not more than 100 images, so 90% of the resources are useless. Moreover such a huge number of images usually will grow frequently(new images will be added) – Archie.bpgc Jan 10 '13 at 05:38
  • Can you refer me to some tutorial related to lazy loading images in listView. The samples i found were a bit complicated for me to understand as i am not very much experienced in multithreading type of programming. Thanks in advance – Swati Rawat Jan 10 '13 at 05:38
0

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.

Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
0

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.

Aditya Kushwaha
  • 839
  • 6
  • 12
0

@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

Community
  • 1
  • 1
Md. Sajedul Karim
  • 6,749
  • 3
  • 61
  • 87