Focus and selection¶
It's important to distinguish between a selection event and a focus event.
You can change the selection state of a DpadRecyclerView while focus is in a completely separate view.
However, when focus changes to different ViewHolders inside DpadRecyclerView (due to DPAD navigation for example), this will automatically fire a selection event.
So, in short:
- Selection changes can happen without focus requests
- Focusing another view triggers a selection event
Focus changes¶
To enable focus changes in your RecyclerView.ViewHolder, you need to set a child view as focusable. Otherwise, DpadRecyclerView won't find it
when the user presses the DPAD.
Do this either in XML or after onCreateViewHolder:
To observe focus changes, simply use a OnFocusChangeListener:
You can also observe focus changes inside DpadRecyclerView with the following:
Selection changes¶
You can observe selection changes using the following:
If your ViewHolder implements the interface DpadViewHolder you can also get these events automatically from these callbacks: