Talkback doesn't navigate to the view above recycler view - android

I am using Recycler view for showing list items. I have made the first view item 'GONE' and set its height to 0. Currently focus is on 2nd item (technically its a 1st item, since the actual 1st item is not there). What I observed is, if I swipe left, the talkback doesn't navigate to the item above recycler view. It gets stuck there.
Note: I have not made any attribute changes, everything is set as default.

Related

Gaps in between recyclerview items when view inside item is shown/hidden

I am using recycler view with linear layout manager, based on some logic I am hiding/showing a view inside recycler view item.
Issue Problem occurs when I scroll, I can see some gaps in between recycler view item, which are random when scroll. If I hide the view always , then there is no issue, but I need to show and hide based on some logic and when implemented the gaps are coming as well.
Assumption One thing I am sure of is that the issue is there because of hiding/showing a view.

Android RecyclerView scrolls to top when child element is expanded/collapsed

I have a list of elements in a recycler view that are generated dynamically using data binding. Each element has a bottom view that is initially set to View.GONE, however once a user clicks the element and the view is expanded, the recycler view automatically scrolls back to the top of the list. Conversely, if the view is expanded and then clicked again to collapse, the recycler view scrolls to the top of the list again. I have tried keeping track of the ID's of the elements for the adapter (again using data binding), setting focus to the child element when they expand or collapse, and using binding adapters to animate the expand/collapse itself.
My suspicion is that the adapter in the recycler view is receiving a onNotifyDataChanged() alert when the height of one of the child changes, rendering an additional view (still inside one of the children though, not a separate child in the list), and automatically scrolls to the top. Is there a way to override this? Does anyone know what else might be causing the list to snap to the top when one of the elements is clicked -> expanded/collapsed?
So I found the solution to my issue in case someone encounters something similar. I actually ended up finding this answer: RecyclerView notifyDataSetChanged scrolls to top position
and the second solution involving the staggered layout manager was the route I went with, since I want to be able to wrap the content. My suspicions were correct that it had to do with the changing height of the elements in the recycler view. The expandable item's parent wrapped content, so the recycler view was forced to recalculate the size of the item once the expandable portion appeared/disappeared (at least that's what I got out of it).

Listview with one sticky header for second row

My layout is a bit complex.
I have a SwipeRefreshLayout in which I host a ListView. Whenever the user drags the Listview's top, the SwipeRefreshLayout performs a refresh. I also listen for the last visible item of the ListView to load next page of records (Endless scroll)
In the list's adaptor I have 2 views that I am using. The first one will only be visible in first row, the other view will remain the same for all other rows.
What I want to achieve:
On top of the row with position = 1 I want to have a sticky header. This means that when I scroll Up, the header will scroll to the top of the screen and will remain in there.
This sticky header will only be at one row
if possible I'd like to use a simple implementation as my layouts and adapters are already complex enough.
Waiting for your suggestions.
I didnt quite get your question the first time, heres the answer attempt round 2.
In your layout add an empty viewgroup (whichever you prefer, though linearlayout seems to work just great), add a scrollListener to your listView and check the position of your sticky view. If its top anchor is below (meaning its visible in the listview) the top of the screen you set the viewgroup visibility to gone, if the top anchor is either touching the top of the screen or below it, you add that view or one just like it to the viewgroup and set its visibility to visible.
You can adjust the position 2 view visibility accordingly to allow for this change to appear seamless. Can help you a bit more once you have some code and are on your way with this change.

Android ListView resets scroll position after first scroll

I have a list view in an Android (JB) app where clicking on a row replaces the list view with another view.
Pressing separate button, adds the list view back to the activity (the idea is that the parent container toggles between the list view and the contents of a single row).
The problem happens when I scroll to a row near the bottom and press it (to replace the list view). After hitting the other button to show the list view again, everything looks fine (including the row states and the scroll position). But as soon as I try to scroll again, it resets the list view to the top. Scrolling after that works normally.
The data source for the list view doesn't change at all. Weirdly, if I change the orientation of the tablet, then scrolling for the first time doesn't reset the list view to the top.
I'm guessing it has something to do with removing the view and then adding back that same view (which is done by calling removeAllViews and addView on the parent).
I'm not sure but I think when you call removeAllViews for some reason it can't save the previous state.
I'm not sure again if it is the best way to solve the problem but what you can do is to save your scroll position before remove it, and after add your views again you can set it.
Something like this:
int posX = listView.getScrollX();
//remove your view
and after:
//add your views
listView.setScrollX(posX);

How to change the background of an expandable list view child that is not on screen anymore

In a setOnChildClickListener, I am able to change the background of a child item with v.setBackgroundResource(R.color.blue); (I can't use an xml list item selector because I am doing some split screen stuff and focus gets lost) I am also able to set the color back when another child is selected. However, when a selected child is scrolled off screen, it does not go back to the original color and when a parent is collapsed, if a child inside that parent was selected, it will hop down to the next parent and change the background of a child in there since the collapsed rows no longer exist according to android. Any tips on how to fix these bugs?
You need to store which item was selected, then make a custom adapter which in its getView() method returns a view with the appropriate background

Categories

Resources