LandL Partners LandL Partners - 1 month ago 6x
Android Question

Android Custom Spinner with Image selection

I am working on a custom spinner, I already understand how to use an ArrayAdapter in order to customise the layout of the custom popup.

The issue I am having however is that I do not want to show the default spinner on my UI instead I want to show an image, then this image will changed based on the item that has been selected, the image would look something like below:

enter image description here

Further to this, is there a way that I can use wrap_content, but to wrap it based on this image size rather than the default spinner size?


If I understood correctly, you want one layout for the value shown in the Spinner proper (layoutA), and a different one (layoutB) for the spinner option views in the popup window?

If that's the case, then it's very simple: in the adapter's constructor, pass layoutA. And then call setDropDownViewResource() with layoutB.

Alternatively, if you have a custom adapter class, you can achieve the same result by overriding getView() and getDropDownView() respectively.

Setting the spinner's height to WRAP_CONTENT should work in this scenario (although I haven't tested that particular bit).