Which is better loading of images for ListView?

I am wondering if which of the two is better in loading images in a listview from web, is it by batch through some number of threads that are running simultaneously or one by one through thread queue?

I have noticed (but I don't know if that is really the implementation) from the youtube app that the images are loaded by batch and it is kinda fast. Even for not only loading images but also requesting some data from the web as well. Does anyone have an idea?


Asked by: Lucas682 | Posted: 25-01-2022






Answer 1

"better" in which way? Performance wise? Developer-friendliness? Usability wise?

A couple fundamental things to consider:

  1. Creating threads is expensive. It's slow and each thread consumes system resources (of course). When creating a single thread for each download, use a managed capped thread pool.
  2. Don't load images if they're not visible to the user. What you should do is in getView() of your ListAdapter, check whether the image has already been loaded, and if not, re-use a thread from the thread pool to do the work.
  3. Be careful with AsyncTask. As far as I know, AsyncTask manages a fixed, application wide thread pool (I think it's capped to 5 threads), so if all these threads are busy loading images, any other task you perform through that class will block.
  4. Don't re-invent the wheel. Does the ImageLoader of Droid-Fu solve your problem? It also implements a cache, so images aren't downloaded twice.

Answered by: John173 | Posted: 26-02-2022



Answer 2

The best way to have this kind of functionality is to have the images 'lazy load' in the list. If your list is of fixed size then run multiple threads (one for each visible list item), download the images and refresh the images in the list. In that mean time have some dummy image placed in the same location.

Have only a fixed number of image components for you list, preferably a few more then the total visible images at any point. Each time the list is scrolled, check whether the image corresponding to the that particular list item exists or not. If yes, display. If not, display the dummy image, run the thread to load the image in background and refresh the list image once download completes.

To further save the memory you can use 'SoftReferences' for the image components. This allows the garbage collector to take away the images that are not being shown on the screen at the moment.

Answered by: Arnold472 | Posted: 26-02-2022



Answer 3

I tried to create a simple lazy list example that may be used as a reference, here it is Lazy load of images in ListView

Answered by: Agata458 | Posted: 26-02-2022



Answer 4

https://picard.hgo.se/~jakeri03/blog/?p=39

this might be what you are looking for, uses a fixsized threadpool and a soft cache to lazyload images.

Answered by: Audrey229 | Posted: 26-02-2022



Similar questions

android - How to pass more than one array to a listview?

I am using a ListView to display items. Currently I am passing a String array of items to it. But I want to pass one more array and display its items along with the items of the first array; that is, somehow having two lines of text. How can I do that?


how to list the audio files in a Listview in android

I am new to this android application development. I have a audio files in a particular directory. I want to list the those audio files in a listView. please tell me how to do this activity.


android - Making child ListView scroll

Hello I am trying to make a terminal type app that is wider than the actual android screen. A listview is great except that I don't want the text to wrap. If the text is wider than the screen I want it to print the full text and then the user can scroll over horizontally if they want to see what was printed off the screen. Just FYI this is for ascii type tables. I have followed this example:


android - display item of listview

I have a list view having several items and it is multichoice list. I want to display the checked item of list view. how i can do this.can anyone help me???


android - Specify view to use when ListView is empty?

I can't find this in the docs - isn't there a way to specify a View to use for a ListView if the adapter is empty? Thanks


How to show a button at the end of an Android ListView

I want to show a button at the end of an Android list view. How can I achieve this? I don't want to stick it to the activity bottom using alignparentbottom="true". Using layout_below does not work for me either. My current XML: <?xml version="1.0" encoding="UTF-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android...


java - android listview button control

I have an android listview filled with items. Every item has a button. This is the template of the my listview. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingBottom="6dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingLeft="5p...


How to set the Listview item size in android?

I have added an adapter to a list view. For some items, the text is lengthy and the item displays only a portion of the text. How do I fix this? Is there a way to set the size of the list view item?


java - Android Layout with ListView and Buttons

Alright, this specific layout is just annoying me. And can't seem to find a way to have a listView, with a row of buttons at the bottom so that the listview doesn't extend over top of the buttons, and so the buttons are always snapped to the bottom of the screen. Here's what I want: removed dead ImageShack link It seems like it should be so easy, but everything I've tried has failed. Any help? ...


android - Layout :How to get the bottom bar under listview

I hope can get the layout like this: -----Search bar(EditTextview)--- -----Listview(Rows)-------- -----Bottom bar(Contain many buttons)--- Pls give many samples Thanks very much I paste my xml file here.Pls help me check it:


android - How to pass more than one array to a listview?

I am using a ListView to display items. Currently I am passing a String array of items to it. But I want to pass one more array and display its items along with the items of the first array; that is, somehow having two lines of text. How can I do that?


Using a ListView to create a settings screen in Android?

I'm developing my first Android application, and I'd like to create a settings screen. I'd like the screen to have a similar look-and-feel as the native phone-settings screens and the native "create/edit alarm" screen. Thus with different kinds of (statically defined) items vertically stacked with a thin line between them. How do I define such screen? I understand I can use the ListView, but this ...


Android ListView Selector Color

Hi All, I have 2 questions regarding a ListView in Android: How can I get the color of the listview's focused row ? I tried to use the ListView.getSelector() method, which according to its documentation should give me what I'm looking for, but it's giving me a Drawable object which I don't know how to retrieve the color from (if possible...).


how to list the audio files in a Listview in android

I am new to this android application development. I have a audio files in a particular directory. I want to list the those audio files in a listView. please tell me how to do this activity.


android - Making child ListView scroll

Hello I am trying to make a terminal type app that is wider than the actual android screen. A listview is great except that I don't want the text to wrap. If the text is wider than the screen I want it to print the full text and then the user can scroll over horizontally if they want to see what was printed off the screen. Just FYI this is for ascii type tables. I have followed this example:


listview - How to popup list like a spinner without spinner in android?

I have a spinner widget in my activity which lets users pick a list name. Normally, the function of the spinner is to switch between lists but for a couple of instances, I swap out the selection change listener to perform a different function with the same list of options. Once the selection has been made, the old listener is restored and life goes on. This is a bad and buggy arrangement. Instead, I would...


android - display item of listview

I have a list view having several items and it is multichoice list. I want to display the checked item of list view. how i can do this.can anyone help me???


android - Specify view to use when ListView is empty?

I can't find this in the docs - isn't there a way to specify a View to use for a ListView if the adapter is empty? Thanks


listview - Round bottom corners on Android Bitmap?

Hey all, what would be best practice for clipping the bottom borders of a Bitmap? Just manipulate the Bitmap itself or overlay an alpha mask drawable or ...? The whole story: I've a Listview which looks like the iPhone's grouped UITableView style. I would like to display a Bitmap in the last row, but for now the Bitmap overlaps my custom background drawable of the Listview cell. Thx in adva...


java - How do I fill a ListView (in Android) with XML or JSON data?

I read a tutorial, and it uses SQLlite and "SimpleCursorAdapter" to fill the list with items. This is the code the tutorial taught me. private void fillData() { // Get all of the notes from the database and create the item list Cursor c = mDbHelper.fetchAllNotes(); startManagingCursor(c); String[] from = new String[] { NotesDbAdapter.KEY_TITLE }; int[] to = new int[]...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top