In my fire tv app I'm using a recyclerview
with horizontal layout
.
Scrolling with dpad works and also items are gaining focus.
But when I hold the button it scrolls very fast because many keydown events are triggered, and items are losing their focus and it's not possible to scroll anymore because another Textview
above my recyclerview is gaining the focus.
It looks like a bug. Is there any workaround for this?
I think the answer by @tmm1 is the best one so far. I have successfully implemented this workaround for the issue of elements loaded in a RecyclerView loosing focus if user uses the DPAD too quickly to scroll.
In my RecyclerView's adapter I use a LayoutInflater to inflate my element views like this
My item_keyboard_key.xml were originally defined like this
Then I created a new custom FrameLayout class (FocusFixFrameLayout) extending FrameLayout and using this as my root layout. My item_keyboard_key.xml then became
and my FocusFixFrameLayout class looks like this
I have faced the same problem. The good news was that popular apps(YouTube and others) do not have this problem. I found informative resource. After investigation I made a solution that is convenient to me. The key is to use Presenter instead of Adapter There is the simplest example
Looks like this is a bug.
See https://stackoverflow.com/a/33190656/332798 and https://issuetracker.google.com/issues/37067220
I was able to work around this bug by neutering
clearFocus()
on my item views, so detached views losing focus did not move focus outside the RecyclerView:I face the same problem, what i do in my project likes below in my Activity (containing RecyclerView):
which avoids the fast scrolling when you hold the button on the dpad, and the focus works fine in my RecyclerView.