Search code examples
androidimagelistviewandroid-layout

ListView and images


I have two problems with ListView+images. I get the values for the list from an xml file which contains all necessary infos.

  1. I need to set up a Listview. Every row should contain an icon and a title. The icon is a local drawable (shipped whith the app).

    An example what I want to achieve can be found here: http://www.tutomobile.fr/wp-content/uploads/2010/07/listViewPerso_1.png

    I need a dynamic way to add images to the ListView, the xml file contents may change.

  2. Is the same as the previous but this time the images are hosted on a server so I need to load them from the server and then display them in the list.


Solution

  • A ListView item can have it's own custom layout. When you create your adapter for the ListView you can pass in the layout id to the Adapter constructor. See SimpleAdapter and ArrayAdapter. You will have to extend an Adapter and implement getView() to property set the image+text.

    Here's a complete sample code How to lazy load images in ListView in Android. You can reuse it.