Mackovich
Mackovich

Reputation: 3573

Accessibility traversal order ignored

I have created a custom navigation line menu on Android TV that consists of a LinearLayoutCompat with AppCompatButtons that each represents an entry in the menu.

The menu is built dynamically, in the code at runtime by inflating the AppCompatButtons and then manually insert them into the parent via addView(...).

Then I set the right order for Talkback in the code:

// after adding the views to the parent
menuItemsViews.forEachIndexed { index, menuItemView ->
    if (index < (menuItemsViews.size - 1)) {
        menuItemView.accessibilityTraversalBefore = menuItemsViews[index + 1].id
    }
    if (index > 0) {
        menuItemView.accessibilityTraversalAfter = menuItemsViews[index -1].id
    }
}

Note: I made sure to call generateViewId() on each of these menuItemsViews after constructing them.

Here is an example of a menu:

|HOME| |PROFILE| |SEARCH| |SETTINGS|

However it does not work: Talkback will never respect the order and choose "Profile" instead of "Home".

To ensure I have properly defined the accessibilityTraversalBefore|After, I have set an accessibilityDelegate in the parent LinearLayoutCompat and overriden onRequestSendAccessibilityEvent to place a breakpoint => everything is correct.


Why does it ignore the order I have defined ?

Upvotes: 1

Views: 490

Answers (0)

Related Questions