e.perrot
e.perrot

Reputation: 139

Keep unpressed state of a child view from a ListView item which is pressed

I have a ListView which contains items with an ImageView in each item. This ImageView has a OnClickListener. I set a XML background to set drawables for pressed and normal states. The onItemClick on the ListView and onClick on the ImageView are fired as expected, but the thing is when I click on the item (not on the ImageView), it also show the pressed state on the ImageView. I want to keep the normal state on the ImageView in this case...

I tried duplicateParentState="false", played with the focus, etc. I didn't find the solution yet.

Does anyone have an idea how to fix that?

Thank you, Erwan

Upvotes: 2

Views: 749

Answers (2)

Seid
Seid

Reputation: 56

I solved this problem by adding clickable attribut to inner items of my listview item. After that listview item not share pressed state with views, which are clickable.

Just add:

   android:clickable="true"

(tested on 4.1)

Hope this could help to someone, I personally could not find so simple solution.

Upvotes: 1

Luke
Luke

Reputation: 3551

I've found in some of my experiments with ListView that only one element in the listitem can support an onClickListener - I haven't found any documentation that supports this idea though.

e.g if you list item contained a checkbox, or a ratingbar then I wouldn't be able to fire an onClick event for the listitem it is contained within

Upvotes: 0

Related Questions