Get RecyclerView to stop scrolling when I add items to the Adapter - android

How can I stop RecyclerView from scrolling to the bottom of the list whenever I add items?
Even when I insert something at the top of the list and call notifyDataSetChanged or notifyItemInserted the list scrolls to the bottom.
The one feature that works as expected is notifyItemRemoved(index)

I think I was calling notifyRangeInserted() with the entire list and that was scrolling to the end of that range.
If you're having similar issues, just cut the Adapter functionality back to its bare essentials and build up from there.

The problem was I had an item in the list, a ProgressBar to indicate that data was loading, but when the new items loaded I added them to the list, this moved the "focused item," the ProgressBar down and if there were enough items to move it off the screen then the RecyclerView would scroll down to keep it on screen. The problem being 1. I didn't want it to maintain "focus" and 2. The very next thing I did was remove the ProgressBar from the `Adapter.
So the solution is to remove the ProgressBar or other items before adding items earlier positions in the Adapter.

Related

RecyclerView animation when for replacing entire DataSet

So I was working with RecyclerView animations, and implemented an animation for when the items load into the List. I was wondering, if I can make an animation for when I replace the entire data set (an animation including the items joining and leaving the RecyclerView).
The correct way to remove an item from a recycler view is to remove the item from the data set and them inform the adapter that the item is removed. If you do this then the animation would happen similar to the animation that happens when you add an item.
myDataset.remove(position); // myDataset is List<MyObject>
mAdapter.notifyItemRemoved(position);//this line is important
If you are not using the second line then...
mAdapter.notifyDataSetChanged()
will be called and the animation will stop.

How to get whole scroll event when removing element from adapter of recyclerview?

I'm trying to create "sticky headers" on a RecyclerView (which uses a LinearLayoutManager) but now I'm facing a problem. When I click on one item of the list, a new item is automatically inserted just below it and the RecyclerView's default animation is shown (the one which smoothly adds and shows the new item). When I tap the initial item again, this new added item is removed, and the RecyclerView's default animation is shown again (the one to slowly hide the removed item).
I have completed all the sticky headers functionality but now my problem is that when I click the last list item and the hide default animation is shown (with a scroll up), my sticky headers don't work. I need to know (and here is were I'm stuck) how to get notified while this RecyclerView animation is being performed when adding/removing items. I need to get notified with all the animation steps, not only the start and end ones.
So far I've tried to use a RecyclerView onScrollListener and a ViewTreeObserver (attached to the added/removed view) but neither worked. If someone could give me some help, it would be really appreciated.
Thanks in advance to all the Stack Overflow community

Nested RecyclerView scrolls to the first item on NotifyItemChanged

I have vertical RecyclerView for scrolling group of items and horizontal RecyclerView in each ViewHolder in order to scrol items inside of these groups. They are populated from database. Whenever item content is changed (user tap something or new data come from network) it is written to database and then notifyDataSetChanged() is called for the group cursor. I check if it is the same group in onBingViewHolder() and update items only if it is. But horizontal RecyclerView is scrolled anyway to the first item.
How could I prevent this behavior and why does it happens ?
BTW I'm writing result of this check in 'onBindViewHolder()` to the log and I can see that it is the same item.
Thanks.
RecyclerView creates new ViewHolder in order to perform animation. setItemAnimator(null) solved my problem.

RecyclerView deleting item doesn't call OnScrollListener

There seems to be a lot of post on how one can scroll up for more posts and I have posted a question on this before: Adding items to Endless Scroll RecyclerView with ProgressBar at bottom
However, I have a question on deleting items in a list on recyclerview.
You have an android app which fetches 5 items from the database server in a page.
As soon as it fetches it, you start deleting items one by one.
The list recyclerview scrolls up but the OnScrollListener is not called as you haven't really "scrolled".
How do I address this problem when I want to add on more items to my list as my delete start eliminating items from the top?
when deleting each item call
recyclerView.smoothScrollToPosition(0);
it works perfectly

Android: How do I remove an item from a gridview, having the remaing items shuffle into place

BACKGROUND:
I have a grid of 36 buttons, lets say a 6 rows & 6 columns numbered 1 to 36, displayed 2 rows at a time via a GridView and custom Adapter
The grid displays fine, and all of the scrolling works properly.
QUESTION:
I want to be able to click on an item, have it removed from the grid and the remain items shuffle up into place. Currently I am able to disable the item disabled, set its visibility to INVISIBLE or GONE, but none of these will actually remove it from the display.
Suggestions?
Specifically, you need to remove the corresponding object from the data set of the underlying adapter and then call adapter.notifyDataSetChanged(). This isn't going to provide you with an animation, though, if that was part of this question.
It may be interesting to try a tween animation for the item in question and then finally remove it from your adapter at the end. I'm not well-versed in animation, so I'm not sure how well this will work in an AdapterView.
You should be able to update the adapter, and then call notifyDataSetChanged to force the grid view to be updated.

Categories

Resources