I am using gallery with custom adapter I have image in gallery which slides from horizontally. Each image has a caption associated with it. What I want is an appropriate title to appear on the header of my screen, if an image is visible.
I am doing this by putting these lines in my getView()
method :
myGalleryImage.setBitmap(myImageBitmapArray.get(position)
caption.setText(myArrayList.get(position)
What happens is my image gallery works fine, but I am not having the appropriate caption with that particular image, i.e. if (I image at position at index 4) then sometimes I get the caption of index 5 and sometimes 3, but never the appropriate caption.
You're constantly overwriting the caption with the last view to load, usually not the centre view but the edge views, hence why it is always 3 or 5 but never 4 - which one it would be is up to the direction of travel.
You would need to use the Gallery method setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener)
otherwise you have to poll horribly to determine when a change has occurred and then I think the position provided will be the centre item (Gallery is a bit of a hack of a spinner so it's a little confusing).
I'm not sure if the position will be accurate if you have more than one on the screen, but once you've been polled you can work out which one is and display that in the caption.
This is not something you want to put in the getView() method because it may or may not be called due to caching and it will never be the right one anyway.