简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM