Javier Pech
Javier Pech

Reputation: 29

Listview with image icon

I am working on an app and I want to display an image beside text in a Listview. My list view is populate by an array adapter and the icon placed beside the text will be the same for every item. I've read around and I have found that I should use a custom adapter and I am new to the android so can anyone give me reference or help me out?

Upvotes: 1

Views: 590

Answers (1)

droidx
droidx

Reputation: 2172

I think this is exactly what you are looking for. http://www.javacodegeeks.com/2012/10/android-listview-example-with-image-and.html

General steps.

  1. Create custom object
  2. Create ArrayAdapter of this custom object.
  3. Override some methods of the Array Adapter. Particularly, the getCount() where you need to return the size of the list of items.
  4. Make sure you implement your logic appropriately in the getView() method.
  5. Also, you mentioned you are using the same image for all the items (mostly you are storing this in your drawable folder and will be pretty straight forward) But in case, you load images from URL, I would suggest Picasso

Hope this helps!

Upvotes: 1

Related Questions