Android Talkback accessibility loosing focus after introducing databinding

Viewed 663

My team is re-architecting an existing MVC based code to MVVM with LiveData, BaseObservable (for Bindable fields) and Navigation Component.

Earlier we had all activities with header fragment as toolkit, now single activity with multiple fragments using Navigation Component. We are reusing the header fragment but it is put inside Activity and only the fragments change below it in the activity using navigation components.

In fragment 2, we have a recycler view with hidden layouts. These layouts are made visible/gone based on BaseObservable fields using data binding from the xml itself.

Here are the layouts..
First row shows the navigation and second shows the issue in fragment 2

enter image description here



Accessibility Issue
It all worked fine earlier while using talkback. But now, when we click an item in the recycler view and expand the item and perform click action on a sub text 1, the new sub text 2 gets visible but is not able to retain the accessibility focus. It has the focus for few seconds and then the focus shifts outside the recycler view to the header tile as depicted in the image. This is causing issue in the accessibility talkback flow.

What is required: the sub text 2 should retains the accessibility focus.

Code Snippet used in onClickListener of sub text 2
old code

holder.subText2.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

new code

binding.subText2.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
binding.subText2.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

Is there issue of using data binding and BaseObservable Bindable field with accessibility?
Or the issue is something else?

How can I make it work and have accessibility focus retained on the sub text 2?

Update
After adding below code, it is working correctly. But I want to avoid the use of view.requestFocus(). Is it possible???

AccessibilityManager am = (AccessibilityManager)context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    if(am.isEnabled()){
        view.requestFocus();
        view.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
        view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
    }
0 Answers
Related