简体   繁体   中英

OnClickListener and OnTouchListener

I have an 2 adapters extending BaseAdapater. The first Adapter (let's call it imageAdapter) loads an image base on an ID, the second adapter (pageAdapter) builds grids of images from the first adapter. I set the second adapter to a gallery. The idea is that I can sort have pages in an album where there are multiple pictures on each album.

Now I want to the imageViews to fire off clicks, so I set an onClickListener for each of the imageViews from the imageAdapter. The problem is that after I set the onClickListener, I cannot scroll the gallery by touch/fling/scrolling on the images anymore. I think it's an issue of parent/children event pass through thing.. but I am not sure how to fix it exactly. Please help.

This is a wild guess based on an experience with ListView (where one clickListener worked but the parent onClickListener did not), but setting the onClickListener on the imageViews might have made it so they have taken away the focus, and now your other touch events are not registering.

try setting myImageView.setFocusable(false)

I am assuming that everything worked as expected before you added the onClickListener to the ImageViews.

I solved this problem by subclassing Gallery and overriding onDown() and onSingleTapUp(). I have to also implement a pointToChildId() method to translate motion events to item ids. =) it was a lot more work than I initially planned for, but it works now and I am quite happy with the solution.

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