Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to shift accessibility focus on RecyclerView's first element on some action?

I am new with android accessibility - TalkBack. I am aware of basic things like contentDescription, importantForAaccessibility and how they make node tree, etc.

In my problem, I want to shift accessibility focus on RecyclerView's first element on some action.

Usually someView.requestFocus() or someView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) works. But it seems to not working as expected in RecyclerView.

I have tried to solve it by:

  1. android:accessibilityLiveRegion="polite" but it only announce that list is there. But it doesn't go on an element with accessibility focus.

  2. By focusing the first element from the adapter - but it's a bad idea to do so!

Other than that, android:accessibilityTraversalAfter and android:accessibilityTraversalBefore also don't work well with a list view in android.

someView.requestFocus()
someView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
like image 761
Dhara Vamja Avatar asked May 29 '19 11:05

Dhara Vamja


People also ask

How to make recyclerview focused list item to display black background?

The main activity layout file with RecyclerView, activity_main.xml The layout file for list item in the recyclerview, the focusable has to set to true, and the background is set to a selector drawable. list_item.xml The background selector drawable, this will make the focused list item to display black background. item_selector.xml

How to make the recyclerview scroll to the last position?

There are 2 ways by which you can do. 1: When you are creating any LayoutManager for the RecyclerView, Make the last parameter in its constructor as true. LinearLayoutManager layoutManager = new LinearLayoutManager (MainActivity.this,LinearLayoutManager.HORIZONTAL,true); 2: Simply tell the RecyclerView to scroll to the last position.

Where should accessibility focus be selected in a Tableview view?

where the user makes a selection. Once the user makes a selection and the presented is dismissed, the accessibility focus (SHOULD?) be selected at tableview cell index 3, but instead the focus is set back to the initial element in the view, in my case most top-left element.

When to use scrolltoposition in reyclerview?

I usually call scrollToPosition when the dataset is succesfully inserted to a RecyclerView, for example: This way, we don't have to wait certain millisecond to scroll a ReyclerView. When there is a new dataset, we can trigger scrollToPosition or smoothScrollToPosition and be sure RecyclerView is scrolled.


2 Answers

RecyclerView's getChildAt() method worked for me.

recyclerView.getChildAt(0).requestFocus()
recyclerView.getChildAt(0).sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
like image 127
Dhara Vamja Avatar answered Oct 21 '22 22:10

Dhara Vamja


Request Focus with Specific ViewId and gets the first element of that node.

like image 35
mini developer Avatar answered Oct 21 '22 23:10

mini developer