views:

22

answers:

1

I have a ListView with custom items - 3 ImageViews and a TextView. I have a call to setItemsCanFocus(true), so I can make the ImageViews clickable. I'm currently using SimpleAdapter to populate the View.

I'd like to trigger the AdapterView's onItemClick event when one of those subviews is clicked. The onItemClickListener receives a view as the second argument and that can be used to identify which subview was clicked. Frankly, I was expecting this to be the default behaviour but it isn't, unfortunately.

Is there any way to implement this behaviour without bluntly breaking encapsulation (i.e. creating an Adapter that holds a reference to its View)?

What is the accepted way of dealing with events from views in list items? How do you keep the Adapter from knowing too much about the ListView?

A: 

Unfortunately you have to choose between using onItemClick() or onClick() on individual children. One way to do it however is to make the top-level view of each item clickable.

Romain Guy
Right. So, I just broke encapsulation by registering an `OnClickListener` with the Adapter and passing it on to each of the child views. Thanks for your answer!
Delyan