The question is : How do I manage to put a listener on elements inside a LinearLayout, itself on a ListView of LinearLayout.
Concretely, I have a ListView, with a list of LinearLayout in it, and each contains a Button and a TextView. I simply want to know if the user is clicking on the Button or the TextView and in which row.
I’m not especially looking for code, but so far, I have a OnItemListener on my ListView and when I click in, it returns the LinearLayout, not the components in.
You’ll have to implement a custom adapter and manually set your listeners for those views(the
ButtonandTextView) in thegetView()method. To find the row where theButtonor theTextViewwas clicked you could first set as a tag the position(the parameter you get in thegetView()method) and then in the listener find out with which row you are dealing with based on the view’s tag. The methodonItemClickwill tell you only what row was clicked in the list.Here is some sample code with the custom adapter:
I used a single
OnClickListenerfor both the views, you could use 2 listeners one for each view followinf the same principle. The full class + layout file could be found here: http://pastebin.com/uM0mb4mq (with gist available here: git://gist.github.com/2625797.git)