androidonclicktextviewsimpleadapter

Android Listview simpleadapter onClick, how to find which view was clickon?


I have a list view that is built using a simpleAdapter, each row is defined by a Layout containing a TableRow and a few TextView.

What should I do to know on which TextView (in the layout) was clicked on?

I am able to get the listview row (position) if I use a OnItemClickListener on the Listview, however it dosen't tell me on which TextView on that row was clicked on.

I would like to take different action depending on which TextView a user click on in a listview

listview

-----------------------
TextView1 : TextView2 |     <--Row1
-----------------------
TextView1 : TextView2 |     <--Row2
-----------------------
TextView1 | TextView2 |     <--Row3
-----------------------

I would like to be able to tell, that row 2's TextView2 was click on.

Hopefully I am explaining myself well enough.

Thanks you


Solution

  • If the click is being handled by onItemClick, then you cannot know from this which View WITHIN that View was clicked. An OnItemClickListener just handles clicking a list item. What you might try is using a custom adapter in which you grab hold of all the Views in the row in getView() and set onClickListeners on them there. Or you can define the onClickListeners directly in your View class if possible.