Paging 3 - Recyclerview scrolls itself when first pages are empty - android

I'm using pagination 3 to load paginated data.
I encountered this problem when the first few pages have empty data. The recyclerview makes an automatic scroll the first items are not visible.
I solved this by scrolling the recyclerview back to the first item as soon as the adapter receives items for the first time, but this doesn't seem like a very good solution to me.
What's the best way to deal with these empty pages? Is there any way to prevent the load Method to send empty pages to the adapter?
Note that the endpoint responses are not completely empty, just the first few pages in some cases.
I can't define which is the first page that contains data before making the query.

Related

How to further optimize android recyclerview?

In the beginning we had listViews. As a developer, we had to recycle and reuse the views to have a fluid experience.
Then, came the recylclerviews. Now, all the recycling heavy lifting is managed by android library itself.
Using pagination, an infinite recycler view can be implemented, which loads the data when needed.
But there is one problem I am still facing in infinite recyclerview. How is the data in the adapter managed?
In most of the infinite scroll implementations of recyclerview, the new data is appended to the original data. This makes the size of data set ever increasing.
Why cant dataset itself behave like recyclerview and recycle its data, instead of appending? (Like a circular queue).
How can one manage the positions of itemviews, when the dataset is a circular queue. Is it unnecessary and yields too little performance improvement? Am I missing some design pattern?
It would be possible to clear data already loaded, but this way you have to load data not only for "bottom" views, but for "upper ones" too. So user wants to back to previous data and he needs to load that data again, that's the problem.
There could be more work about notifying data set changed in recyclerView.
You can implement it this way, but remember about pagination and how it is implemented - for example limiting data in SQL statements standard way can output different data each call, so user backing to previous data can see other results! Check Twitter pagination for one of the way to achieve same results each time.
Pros:
less data in memory
Cons:
more work to write the code
more data loading for users (more internet usage, more loading times - when users wants back to previous data)
pagination has to be designed more carefully

android dynamic listview with scroll

I'm creating an android book that use data from database(sqlite) and has six season.
my data is about 1MB and for loading data on listview is slow.I wanna to put a dynamic listview for my project that load 10 item on listview with scrolling each time.
please help me
ListView actually keep in memory items only visible for users - check it for better understanding - http://android.amberfog.com/?p=296.
I think you are talking about lazy loading data from sqlite, so just fetch next 20 (or whatever) items when user scrolled to last item.
I recommend you to switch to RecyclerView. Please check that article for implementation of endless scrolling with RecyclerView.

Android ListView - Setting adapter in a background thread to improve performance?

Situation
I have 3 tabs and currently when I swipe between the tabs there's a lot of lag. Each tab contains a ListView that has an image of a user, and two TextViews with the user's name and a small description (kind of like WhatsApp). Earlier each ListView would also lag and not scroll smoothly, but I went through this guide from the android developers website and then I modified my app to load the images in an AsyncTask and also implemented the ViewHolder pattern. Now, the ListView loads scrolls smoothly, but it takes time to scroll for the first time. In other words, when the ListView is scrolled for the first time it lags, but then it becomes smooth. Another thing you should know is that the data that is populated into the ListView is loaded from a SQLite DB.
Hypothesis
I hypothesized that the reason for this is that even though I'm loading the images in an AsyncTask, because I'm reading content from a DB prior to setting the adapter, that DB access is causing the tab switch and the subsequent first-scroll to be slow.
Question
Will reading the DB in an AsyncTask and then setting the ListView adapter in the onPostExecute method improve my performance? If yes, what's the logic behind it?
I have a bad feeling it wouldn't make a difference because the ListView will be drawn only after the data is provided through an adapter. Here, however, we're loading the data to be fed into the adapter itself from a DB in an AsyncTask.

ViewPager or ViewFlipper or something else for unlimited set of data?

My source of data can me give unlimited set of data (it's like days in calendar). I have to show each item separately on screen (one item at a time). For each item I have to make query into my data source. I don't know which approach will be better ViewPager (how handle in adapter unlimited count?) or ViewFlipper? Or maybe there is a third solution (the best one).
Can you put some links to examples. :)
If you are only showing 1 item at a time, use ViewPager
If you want to show multiple items on the same page, use RecyclerView.
For calendar, it seems more close to ViewPager

Android dynamic listView: removing items that are not displayed from ListView adapter

I'm going to implement a dynamic ListView: By spending little time, ListView will populate more items from a local file when you are scrolling downward.I used technique like this to implement such dynamic list:http://mobile.dzone.com/news/android-tutorial-dynamicaly
Problem: Number of Items to be displayed is too large. So if I just keep adding them to data source of ListView Adapter, data source will consume too much memory and finally it will lead to application crash by scrolling more and more.
Question: How can I remove some of items that are not displayed from datasource of ListView such that user do not get noticed? It is not important that user need to wait while scrolling up/down for fetching data.
when you are using listview using base adaptor then adaptor will automatically get called whenever user perform scroll and auto destroy unseen elements.

Categories

Resources