• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Adding onClick handler to View in list item

  • Thread starter Thread starter Deleted User
  • Start date Start date
D

Deleted User

Guest
Hi,

I have a ListActivity where the list items are defined in another XML layout. The list item layout contains an ImageView, a CheckBox, a TextView and such.

What I want is to set an onClick listener to the CheckBox in each list item. That is easy enough. The trouble is I need that onClick handler to know which position in the list it is.

I'm attaching the listener to the CheckBox after that list item's View has been inflated in getView of my Adapter. The getView method has a position parameter, but I cannot reference it in the onClick handler for my CheckBox. I understand why, but I don't know how to get around it.

How do I accomplish this?
 
How about defining an onListItemClick() method in your ListActivity class, and check the checkbox programmatically from that one? That would give you the position, and also increase the surface area the user can click on.
 
Back
Top Bottom