Question

The problem

Suppose you have a view inside a layout view, and you wish that each touching event on the layout would affect the view's background selector.

for example, when you touch the layout , the selector of the view will choose the state_pressed state.

What I've tried

I've read about duplicateParentState and addStatesFromChildren , but I think it's the opposite of what I'm searching for.

I've also tried to use splitMotionEvents, but it didn't help.

The question

How do you do this?

Also, what should be done in case the layout is inside a listView (as an item within it) ?

Was it helpful?

Solution

Consider you have a spinner inside a linear layout. Make focusable property of view(here that is spinner) to false. And onClick of linear layout call performClick on view(spinner in this case).

EDIT:

In focus Change Listener of linear layout if it has focus, call requestFocus on view. You can follow same method to other states of view

Another method:

do not apply any selector to layout(linearlayout in this case) and add whatever selector you want to view(spinner in this case). For view add this parameter

android:duplicateParentState="true"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top