1. Are you ready for the Galaxy S20? Here is everything we know so far!

Adding onClick handler to View in list item

Discussion in 'Android Development' started by andywhoa, Aug 12, 2010.

  1. andywhoa

    andywhoa Well-Known Member
    Thread Starter

    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?
     


  2. meskiukas

    meskiukas Newbie

    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.
     
Loading...
Similar Threads - Adding onClick handler
  1. Kupferrot
    Replies:
    1
    Views:
    188
  2. danezeq
    Replies:
    5
    Views:
    319
  3. Hegmann Kris
    Replies:
    0
    Views:
    275
  4. 808tennis
    Replies:
    1
    Views:
    170
  5. App Update
    Replies:
    0
    Views:
    149
  6. Bayberw
    Replies:
    1
    Views:
    398
  7. PeterMikeWarden
    Replies:
    12
    Views:
    328
  8. App Update
    Replies:
    1
    Views:
    286
  9. CatalinZ
    Replies:
    4
    Views:
    523
  10. Usalabs
    Replies:
    0
    Views:
    142

Share This Page

Loading...