views:

15

answers:

1

Hello,

I'm a bit stuck as to the best strategy to achieve the following:

  • I've got an array of images, which I want to display in a Gallery.
  • I want each image to have a small icon overlayed inside it, on the bottom right hand corner (e.g. a light bulb).
  • When the user clicks on the image or the icon, the icon will change from the 'lighbulb_off' image to the 'lightbulb_on' image, and the index of the clicked image will be added to a Vector of 'clicked images'.

Is there a way to have a custom layout for each item in a Gallery? If so, each gallery item could be the original image, with the icon positioned within it using a RelativeLayout.

Any help would be appreciated!

Cheers, r3mo

A: 

Is there a way to have a custom layout for each item in a Gallery?

Yes. You need to extend ArrayAdapter and override getView() to do what you want. Here is a free excerpt from one of my books that discusses the concept -- while it uses ListView as the example, the same technique should apply for Gallery.

Note that this excerpt should be updated in the next ~12 hours to be much improved, so, um, don't rush to download it right away. :-)

CommonsWare