focusSearch

open fun focusSearch(focused: View, direction: Int): View(source)

Since RecyclerView is a collection ViewGroup that includes virtual children (items that are in the Adapter but not visible in the UI), it employs a more involved focus search strategy that differs from other ViewGroups.

It first does a focus search within the RecyclerView. If this search finds a View that is in the focus direction with respect to the currently focused View, RecyclerView returns that child as the next focus target. When it cannot find such child, it calls onFocusSearchFailed to layout more Views in the focus search direction. If LayoutManager adds a View that matches the focus search criteria, it will be returned as the focus search result. Otherwise, RecyclerView will call parent to handle the focus search like a regular ViewGroup.

When the direction is FOCUS_FORWARD or FOCUS_BACKWARD, a View that is not in the focus direction is still valid focus target which may not be the desired behavior if the Adapter has more children in the focus direction. To handle this case, RecyclerView converts the focus direction to an absolute direction and makes a preliminary focus search in that direction. If there are no Views to gain focus, it will call onFocusSearchFailed before running a focus search with the original (relative) direction. This allows RecyclerView to provide better candidates to the focus search while still allowing the view system to take focus from the RecyclerView and give it to a more suitable child if such child exists.

Return

A new View that can be the next focus after the focused View

Parameters

focused

The view that currently has focus

direction