I'm building an Android magazine-reader for our campus publication that pulls articles from a web service and displays them in a ViewPager.
To minimize the initial loading time, I want it to pull a relatively small number of articles (say 10) to begin with. Once it has pulled and displayed those articles, I want it to immediately begin downloading/deserializing the next 10 articles while the user is looking through the first set. Likewise, when they reach the 11th article I want it to go ahead and download the next 10, so that the user can continually browse without ever having to wait for more articles to load. This seems easy enough to accomplish using AsyncTasks, but I've hit one small hitch: When the next set of articles is downloaded and added to the ViewPager, it jumps back to displaying the first page.
How can I add views to the end of the ViewPager's dataset without changing the article being displayed to the user?
you will want to use the Endless Adapter created commonsware.
Or you can open the page again after refreshing the content of the ViewPager. Get the article id of the article user is reading. Open the same article after the ViewPager is refreshed.
Related
I'm wondering how it can be handled.
I have a paginated list that needs to be refreshed pretty frequently. If I go to details of an item, and then back, I'd like to have current data but not lose everything I fetched previously (for example, if I fetched 3 pages I don't want to refresh only the first one). I think that is a common case, but I'm not sure how other people solve it.
My propositions:
Always refresh no matter what and ignore scroll position.
Request changes that happened between the last update and the current time from the backend.
Don't refresh anything, just inform the user that the list may not be up to date, and give the user button for refreshing if they want.
Send push from the backend every time something changes and handle it in the app.
What I suggest for your problem is either of the 2 solutions -
Refresh the screen but before refreshing take a note of the scroll item user was viewing previously, and then refresh the list and scroll to the item if found in the list else just scroll to the top and show a message "List has been refreshed".
Request changes that happened between the last update and the current time from the backend and then update the list accordingly same as the first solution.
The second approach is much improved and optimised if your backend permits that.
Happy to help,
Thanks & Happy Coding
I'm creating android tv app but I don't know how to implement endless scroll in Verticalgridfragment, i use ArrayObjectAdapter, can someone help me do that?
I'd love to give you a full answer with oodles of code samples but I'm not at my work computer. Basically you'll implement the onItemSelected listener in your Browse/RowsFragment (it should be something like setOnItemViewSelectedListener() from your fragment).
Then you do a check to see if the currently selected element is within 5 or 10 or 15 elements from the end of the list. If it's within that threshold, then make the request for the next page of your list and call addAll() on your adapter when you get the next page. You can optionally show a "loading card" while the next page request is in flight and remove it when you get your data.
I based my implementation off of this open source project - while it's not perfect it should be enough of a code sample to get your started.
I'm building my Android App using Viewpagers, and I built a ListView that takes 8 seconds to show the full Items.
The page doesn't update the view automatically, thats why the Listview appears empty when it is shown for the first time.
So, I was thinking about creating a new page called loading, and hide the page with the listview, and only show it when the Listview items are already there.
To do that, I would like to know how can I hide pages.
I tried to use an Handler and change the number of pages after 8 seconds, but it didn't work, can you guys give me any idea of how can I do that?
Thanks.
You shouldn't create a new page called loading,it is not a good way to solve it. You can u get data in oncreat first time,then update data by a timeror handler+timertask and so on.
I am attempting to implement an "infinite" scroll type of feature in my app. The feature will display a list of items. Each item will contain images, text, etc. When the user scrolls down, more items will appear. I would like to know how "cacheing" algorithms works in popular apps and what is the recommended way to implement them.
The problem that I am having is that if the user visibly goes through 100 items, a lot of in-app Memory is used up. This causes the app to crash after seeing many items. I'm convinced that I should store some of these assets onto the File System of the phone and then re-use them once it's seen again. Please correct me if I am wrong.
For example:
Facebook
In the News Feed, as I scroll down, many "news items" contain images/videos/text. If I scroll through 20, everything looks great. As I scroll down quickly to the "bottom" of the news feed after >40 items, it appears to halt for a split second to "load" more items.
Then, when I scroll back up the news feed, it will display the previously viewed items fairly quickly. I guess my question is, are only a limited # of items cached in memory and most items cached on the file system?
How does it work? I assume when the user sees new news feed items , the app must "download" the assets from the Facebook Server. However, if these items become un-visible, and then the user scrolls back to these items, are these items re-downloaded, retrieved from memory cache, or retrieved from file cache?
I am implementing an ebook reader for android. I have done the pagination part successfully. But it takes a long time to load the book. what I did was, get the raw html and break into chapters and store them in a array. Then get the entire string and using Html.fromHtml I removed the html tags (because I am using view pager and need to get the no of pages, for this reason we need to remove the unnecessary strings first). Then according to this answer I am breaking into pages. (The logic was to get a sub string and check the string height is greater than the screen height, I am checking this condition at every space in the string).
I have used epub-lib library and jsoup for this project. I am using dynamic textviews and Imageviews for this.
Now I need to optimize this process. How to do this? My idea is to load and show the initial pages to users and while the user going through them the rest of the content should be paginated and loaded using a background process.
Is this possible? I am happy to get any other suggestions as well.
Thanks
Yes that should be possible. I had a similar situation where I had a ListView that potentially listed thousands of items from a database. Instead of loading everything, I simply read the first 9 items, displayed them and then had a listener for when the scrolling had reached the bottom of the list and then updated my listview to include the next 9 items.
Also, from a performance perspective, if your book is very large, I'd suggest doing that sort of parsing work immediately after you've downloaded the file in an AsyncTask. I would break down the pages of the book into different objects (i.e. page 1, 2, 3 in a "page" object) and then when you need to display that page, you simply read and display that object. This would also be beneficial if the user opens the ebook multiple times, as you won't have to parse the entire html file again each time that ebook is opened.
The logic would be as follows:
Download the text html
Remove the formatting and get raw text
Break the text into pages
Save each page (or a few pages together) in a "Page" object
Display the first "Page" object
Listener for scrolling to the end of the page
Display the next "Page" object
Repeat Steps 6, 7