How to customize focus navigation in a ViewGroup
-
05-07-2019 - |
Question
I have a View Group and it has 2 focusable Views as its children. I would like know how I can customize how focus is being passed between these 2 Views. In other words, when I press the Down Key or the Up Key in the emulator, i want to control which of these children has focus.
I read the JavaDoc of ViewGroup, I see these 2 methods.
public View focusSearch (View focused, int direction)
public boolean requestFocus (int direction, Rect previouslyFocusedRect)
But I am confused which of these method I should over-ride to achieve what I want.
Thank you for any advice.
Regards,
Solution
you can also try using android:nextFocusDown
attribute, like in focus_3.xml example from the ApiDemos
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow