ListView and click event propagation from child views in items

I have a ListView with custom elements - 3 ImageViews and TextView. I have a call to setItemsCanFocus(true) , so I can make ImageViews available. I am currently using a SimpleAdapter to populate a view.

I would like to trigger the AdapterView onItemClick event when I click on one of these subzones. onItemClickListener receives the view as the second argument and can be used to determine which subtitle was clicked. Honestly, I expected this to be the default behavior, but unfortunately this is not the case.

Is there any way to implement this behavior without directly violating encapsulation (i.e. creating an adapter containing a link to its representation)?

What is an acceptable way to view events from views in list items? How do you not let the adapter know too much about ListView?

+2
source share
2 answers

Unfortunately, you need to choose between using onItemClick () or onClick () for individual children. One way to do this, however, is to make the top level view of each item clickable.

+3
source

Setting android:addStatesFromChildren="true" in the list in your xml will send clicks on children to the onItemClick method in the onItemClickListener connected to your list.

+4
source

All Articles