Joshua
Joshua

Reputation: 371

Adding a series of images in drawable folder to list view

I have currently have the same code from the android list view tutorial. I want to use the images saved in my drawable resource folder and assign each individual image to a specific row in the listview.

I have tried to put an imageview in the xml and this resulted in only the use of the same image for all rows in the list view but I need to use a different image for each row.

I feel I need to create an array of these images and then add them to the listview using the .java file associated with the listview. If anyone can help, it would be much appreciated, thanks.

Upvotes: 2

Views: 1865

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007554

First, as Mr. Roth suggests, you need a custom adapter. Here is an excerpt from one of my books that goes through that process.

With respect to:

and assign each individual image to a specific row in the listview

That is an unusual requirement. If the list will be fairly fixed, you could create an array of the resource IDs (R.drawable.foo) and build your custom ArrayAdapter around it.

Upvotes: 4

Related Questions