I've implemented a cursor backed ViewPager, where I'd like to enable the user to add or remove items. However, deleting a page causes janks in the viewpager.
I'm currently manually scrolling to the next page using viewPager.setCurrentItem(NEXT_PAGE_NO, true); after deletion and scrolling back in the adapter after updating the data set. This does work, but only half of the time.
Is there any proper way to animate it? A solution or a workaround, both will do.
Related
In my Adapter class (AnyListAdapter.kt) i am loading data using API but everytime i perform an action on particular item my whole recyclerview list clears and then data again load from API.
What i have to do is:
As soon as i perform an action on item in recyclerview whole list reloads and items get updated without blinking or fluctuation.
i Dont want to clear my list and load it again i want to reload it withou showing.
Can anyone help in this i am stuck at this not able to find any soultion.
onButtonClickListner{
ClassPerformActionOnItem()
}
fun classPerformActionOnItem(){
//Performing my action on item
//image visiblity,text visibility etc.
item.clear()
CallAPI()
}
the above code snippet is example of what i am doing.
is there any way to reload item without clearing and again showing as it is giving blinking effect.
Don't call item.clear() inside classPerformActionOnItem. Wait for the API call to finish and once it is really done, replace the items.
This should improve your situation but it will probably not completely solve the problem.
To completely get rid of the problem, convert your RecyclerView Adapter to a ListAdapter.
A ListAdapter is a speciall kind of RecyclerView.Adapter which checks the difference between one set of data and another. It can automatically animate the changes in a RecyclerView by animating items in, out and move them around.
Check out this guide for the implementation.
i am using a recycler view with a list adapter. When submitting a list with a completely or almost completely different items the animation doesn't look good. Another problem is that i have no control on the scroll position as scroll to position is not processed as expected. It makes perfect sense to reset the scroll position to zero when the data is changed.
I ended up setting up a new adapter when switching all the data.
Would be helpful to have a better solution.
I would expect to have a method where you notify the adapter/recycler view that you want to switch all the data without trying to applying the diff mechanism and animating the changes.
I would like to be able to animate the appearance of the new list but avoid trying to animate what actually changed.
I am learning android paging library and everything works perfectly. But whenever I invalidate the DataSource, the list is jumping to start position whenever a new item is added to the top of the list. I want to the list to add the item to top. But the list should stay in its current scrolling position. I think I should use LoadInitialParams.requestedInitialKey which is not null when invalidating. But am not sure how to use this key to load data to avoid jumping of list to start position.
I am using firestore database as data source. I found that the requestedInitialKey supplied to the callback is actually the last visible item in the recyclerview in current scrolling position. I have already tried the following to fetch data around the requestedInitialKey
.get().startAt(requestedIntitalKey).limit(25)
.get().endBefore(requestedIntitalKey).limit(25)
.get().startAfter(requestedIntitalKey).limit(25)
.get().endAt(requestedIntitalKey).limit(25)
where 25 is my page size. None of the above solved the problem. Can someone provide me with an example so that the list will stay at its current scrolling position only updating the content without jumping to start?
Are there any best practices on using the new RecyclerView animations together with a SQLite database?
In particular, I'm thinking about a pattern that's been around for a while now: sliding a list item off the screen to delete, and giving the user the option to undo.
Like in the Gmail app:
I don't think this is hard. My approach to solving this is in two parts, a custom view that shims around the adapter view, and a scroll listener on the recycler view.
The custom view is to handle the sliding item part. The key part is to mark the associated item for deletion when it is put into the slid state. I also like to allow for a second slide to dismiss the undo option.
The scroll listener on the recycler view simply deletes any marked items when onScrollStateChanged is called, you only need to care about changes away from SCROLL_STATE_IDLE. I prefer my deletion to be more lenient than the gmail implementation, so I post a delayed message on the scroll event rather than deleting straight away. You have to remember to cancel it if undo is pressed.
Oh, you also have to do any deletions if the screen is navigated away from.
You need to implements SwipeDismiss, use this library
SwipeDismissRecyclerViewTouchListener.java
On dismis you need implements a custom view or use visibility GONE from xml.
I am having trouble finding the event to bind in the ListView adapter to scroll the listview to the bottom when a new item is added. When I initially populate the list its scrolled to the bottom which is correct but on an subsequent adds to the lists via a polling service it doesn't seem to stay on the bottom and I am forced to manually scroll. I am just wondering what events I need to hook into in order to set the index or automatically scroll to the bottom.
Okay I just noticed that when I add another item it pushes up 1 so it seems 1 item is always hidden when I add a new one, not quite sure how to fix this.
After doing more research I realised the error was due to me updating the collection on a different thread. Needed to be on the UIThread.
https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/Working%20With%20Collections/Collections.Droid/Views/PolymorphicListItemTypesView.cs