9

I have four TextViews, and I'm trying to control the order that they get focus when a user navigates using TalkBack and touch gestures.

TextView android:text="foo" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="@+id/id_foo" android:nextFocusDown="@+id/id_baz"/>

TextView android:text="bar" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="@+id/id_bar" android:nextFocusDown="@+id/id_qux"/>

TextView android:text="baz" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="@id/id_baz" android:nextFocusDown="@id/id_bar"/>

TextView android:text="qux" android:clickable="false" android:focusable="true" android:focusableInTouchMode="true" android:id="@id/id_qux" android:nextFocusDown="@id/id_foo"/>

When a user turns on TalkBack, touches "foo", and then swipes down to navigate between the TextViews, I want the order to go foo->baz->bar->qux. But, the order I try to set up using nextFocusDown seems to have no effect, and instead focus order always just follows the positions of the TextViews on the screen. I've tried every possible combination of clickable, focusable, and focusableInTouchMode. I've tried calling setNextFocusDownId on the views in code. I've tried setting android:imeOptions="actionNext" on the TextViews. Nothing seems to work. What am I missing?

Zulu
  • 8,765
  • 9
  • 49
  • 56
Norioch
  • 91
  • 1
  • 3

2 Answers2

4

Try to use View.setAccessibilityTraversalAfter(int) and View.setAccessibilityTraversalBefore(int) to configure TalkBack navigation. Please note that TalkBack has only two directions:

  • forward (swipe to the right or down)
  • back (swipe to the left or up).

Example:

findView(R.id.bar).setAccessibilityTraversalBefore(R.id.quix);
IPhone Guy
  • 699
  • 7
  • 6
3

NextFocusDown doesn't refer to TalkBack gestures. It refers to track-ball and keyboard arrow key navigation. TalkBack exploration gestures are limited to swiping down/right for next focus, and swiping up/left for previous focus. And of course, drag to explore.

MobA11y
  • 18,425
  • 3
  • 49
  • 76
  • but... is there a way to set the next and previous focus? – conca Feb 25 '15 at 16:43
  • I believe what your looking for is nextFocusForward. https://developer.android.com/reference/android/view/View.html#attr_android:nextFocusForward Forward focus and backward focus are reflexive. So if you set "nextForwardFocus" to be an element, that element's nextFocusBackward, would be set automatically. Ex: element1.setNextForwardFocusId(element2.id), would automatically set element2's nextBackwardFocus to be set to element1. – MobA11y Feb 25 '15 at 20:27