6

I have a nestedscrollview within my layout which contains few texts, buttons and recyclerviews.

When talkback is on, I am able to traverse through all elements. But I face an issue. When my horizontal recyclerview is scrolled and then I swipe to hear the talkback, the focus moves to the toolbar first item. Then I need to traverse through all the visible items to reach to the horizontal scrollview scrolled item.

This issue arises only for recyclerviews within nestedscrollview.

My nestedscrollview in layout is added in this manner:

<androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        //my contents

</androidx.core.widget.NestedScrollView>

My recyclerview in layout is added in this manner:

<LinearLayout
     android:id="@+id/photosLL"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical">

     <androidx.recyclerview.widget.RecyclerView
          android:id="@+id/photosRV"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          tools:listitem="@layout/list_item_photo" />
</LinearLayout>

Is this expected behaviour or if its an issue, how to solve the same?

Anju
  • 9,379
  • 14
  • 55
  • 94

1 Answers1

3

Here is a quote from the first link I offered at the end, which I think is relevant to your problem:

"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."

I think what you need is to set these attributes on 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
  • It worked for the first time. But then moving backward and forth was skipping the first and the last element in my recyclerview. Any clue on that? – Anju Jan 04 '21 at 13:29
  • Could you explain it more? Does the view recreates? If not, it should not repeat from top. It has the last focused view saved. – Sina Jan 05 '21 at 11:50
  • I have a heading "Gallery" and below that set of images inside recyclerview. Below recyclerview I have other textviews. When talkback is ON, on swiping forward first focus goes to gallery, then each imageview, and then the textviews. But goiing back from textview to the imageviews doesn't focus on the last image. Focus is going to the 2nd last image. Swipe backward again traverses through the images behind and when I reach the 2nd image and then move backward focus is going to the "Gallery" title. – Anju Jan 06 '21 at 10:18