2

Background Info

When the user opens the bottomsheet, they are presented with a RecyclerView: The recently-selected item in the RecyclerView is auto-selected and then announced with

lastSelectedView?.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED)

that's made possible with (during onCreate)

private fun applyCustomAccessibilityDelegate(view: View?, textToSay: String) {
    view?.setAccessibilityDelegate(object : View.AccessibilityDelegate() {
        override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfo) {
            super.onInitializeAccessibilityNodeInfo(host, info)

            info.className = ""
            info.contentDescription = textToSay
        }
    })
}

i.e. applyCustomAccessibilityDelegate(lastSelectedView, "blah blah")

So far so good

Swipe to focus on views experience

Unfortunately, when the user swipes (single finger) left or right in an attempt to select the next item in the list, the accessibility system neither selects the next item in the list nor the RecyclerView itself - it actually focuses (and announces) on some view outside of the bottomsheet.

I've experimented with View.requestFocus() but it makes no difference in any way! Despite requestFocus() returning true (for focusing on any nearby view), swiping left or right sets focus on a way-off view instead of a neighboring view.

No matter what, it seems the user has to swipe left and right multiple times to get focus back to the recyclerView.

How can this be improved ? Why doesn't Android select the next item in the RecyclerView when the user swipes left or right ?

Someone Somewhere
  • 23,475
  • 11
  • 118
  • 166

1 Answers1

3

I think what you need is to set these attributes in your recyclerView:

 android:focusableInTouchMode="true"
 android:descendantFocusability="beforeDescendants"

If you are looking for more information, read:

Difference between focusable and focusableInTouchMode

and

explain descendantFocusability = afterDescendants

Sina
  • 2,683
  • 1
  • 13
  • 25
  • from firtst link: "In touch mode, there is no focus and no selection. Any selected item in a list of in a grid becomes unselected as soon as the user enters touch mode. Similarly, any focused widgets become unfocused when the user enters touch mode." – Sina Sep 29 '20 at 08:58