I have a listview with each row a linear layout with a textview and an adjacent imageview. I've been able to implement setOnItemClickListener() with the functionality I want, this gets triggered when a row is clicked but I want it to be called when the imageview in the row is clicked. Any ideas?
-
1Attach the listener to the imageview instead of the row by calling the set on the imageview instead of the row. – G_V Jan 22 '15 at 12:38
-
you can add a onclick listener on imageview in the getview(). – droidd Jan 22 '15 at 12:38
3 Answers
you can set click listener on custom generated view items
put this code in your custom xml imageview file.
android:focusable="false"
android:descendantFocusability="blocksDescendants"
and set onClicklistner on imageview
you can also read : Android : How to set onClick event for Button in List item of ListView

- 1
- 1

- 1,490
- 12
- 23
If you wants to add both listview row item click and click event of Image View which is in row layout thn give use android:descendantFocusability=“blocksDescendants”
in row layout's root view
If u r using BaseAdapter** To Apply click event of imageview instance which is created in getView method of BaseAdapter

- 5,015
- 1
- 28
- 56
For this case you can add click listener to the instance of imageview which is created in getView method of your BaseAdapter. if you are following HolderPattern thn below is the exmple code
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
And you also have to add following line in parent layout of your list row:
android:descendantFocusability=“blocksDescendants”

- 5,015
- 1
- 28
- 56

- 1
- 1
- 13
- 20