Reputation: 22023
Hey guys, I've been at this for a while, and I haven't found the solution that works 100% just yet.
I have an Android Gallery which cycles through items, each consisting of an ImageView (let's call it Thumbnail) and another View below it with some text and a little icon (let's call it Title).
What I would like to achieve is 2 different actions based on where the user clicks, all without disrupting the way gallery flings left and right.
For example, if clicking on a Thumbnail, I'd like to do action A (e.g. pop up a larger version), and when clicking on the Title, I'd like to do action B, say pop up a toast with the title of the picture.
There are 2 approaches to the problem the way I see it:
Attach an OnItemClickListener to the Gallery item from within the main view containing the Gallery and then attach an OnClickListener to the Title from within the Gallery Adapter.
While this approach works, it seems to prevent the gallery from flinging if grabbed and dragged by the Title.
Since onClick returns void, there seems to be no way of passing the onClick event down to be handled later by the Gallery's onItemClick.
Since I'd like to be able to fling using the Title, this approach doesn't work for me, at least in its current version.
The 2nd approach would be to have all the detection logic within the Gallery's setOnItemClickListener.
If there was a way to figure out whether the view clicked on was the Thumbnail or the Title, everything would be very simple, and the fling would be intact.
But, I can't figure out how to do this just yet.
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
// TODO: figure out which view has been clicked on, but how?
}
}
Since I use the endless adapter with ViewHolders paradigm, I tried printing the values of these:
Log.d("IDs", v.getId() + " " + ((ViewHolder) v.getTag()).thumbnail.getId() + " " + getSelectedItemId() + " " + parent.getId() + " " + parent.getItemIdAtPosition(0));
but they were all different after clicking on, say, Thumbnail:
-1 2131230800 -9223372036854775808 2131230865 0
So, now I'm stumped. Wise Android community, can you help me?
Thank you.
Upvotes: 2
Views: 1648
Reputation: 2087
I have a solution for you: SwipeView. It's an open source project of mine, checkout the latest source on github (the binaries on my website are a bit out of date and a lot of bugs to do with the sort of thing you are talking about have since been fixed)
https://github.com/fry15/uk.co.jasonfry.android.tools
Theres a demo project here: http://jasonfry.co.uk/?id=28
Enjoy!
Upvotes: 1