Let's say I have a custom ViewGroup which is focusable and has some child views which are focusable as well (A custom vertical menu for Android set-top-boxes which should react on remote controller).
I need to pass a focus to some of the child views whenever the custom ViewGroup gains the focus.
I set descendantFocusability
to beforeDescendants
and set OnFocusChangeListener
to the custom ViewGroup but OnFocusChangeListener.onFocusChanged()
is never called. It looks like beforeDescendants
does not work as I expected. Actually setting the beforeDescendants
works the same as setting the afterDescendants
- The focus is taken by the nearest child view and the custom ViewGroup does not have an opportunity to decide which child view should take the focus.
How can I achieve the desired behavior? What are the best practices to handling focuses in ViewGroup
s?