Autogrowing RecyclerView From Json Feed - android

I have a json feed. I have to display the data in a recyclerview, I have done this in a smooth way, and it works. the feed contains information about 50 movies and if i change the limit in feed link i will get more details (ex : https://myfeed_example.com/rss/topmovies/limit=50/json) if I change the limit to 100 I will get 100 feeds, thats how it works, right now how I am parsing is first I am fetching the whole json feed and iterates through and shows in a recyclerview. that means it will display 50 movie details in the list.
but what I want is first I have to show details of 20 movies, and when the user reaches at the bottom of list, have to load remaining 20 and so on. there are two ways we can follow for this.
If a real time json reader is available, we can read parse feed and
display
We can download all the feed for the first time and and parse all and put in memory and load required data, like that we can do.
which is the correct approach for making an autogrowing list ?

The first option is the correct one.
Then in your Recylcerview adapter append to the list of movies using something like this.
public void appendMovies(List<Movie> movies) {
int size = mMovies.size();
mShots.addAll(movies);
notifyItemRangeInserted(size, mMovies.size());
}

Related

How would I go about displaying data from an API website and putting it in text format on an activity page?

I want to show data in a sensible form for my movie database app. The website I am using to extract data from is www.omdbapi.com. I have already created a code that extracts the title and year of the movies and displays it in a ListView form which contains items that are all clickable to another activity. I would like each activity that the ListView item clicks to to display the movie information under different headers etc.
I have been stuck on this issue all day. I'm new to coding and have no clue what most processes are called etc. Im not asking for the entire code, just instructions on what to do because I am stumped. I would be very very grateful.
Thank you.
Depending on the format the response is formatted you would either use (probably) an xml parser or a JSON parser and grab the info between specific xml tags or the specific keys within the JSON output.
There are thousands of examples of both methods. If you can get the title to display, then you already know how to get the other elements.

How to get JSON data from reddit after the first page

So I am currently making an app to work with and learn more about JSON (using GSON) and decided to go with a reddit browsing app. I am currently able to get the JSON data by using "http://www.reddit.com/.json" and this will get me the JSON for the first 25 posts. I am trying to get the information for the next posts by using
"http://www.reddit.com/.json?count=25&after=" + name_of_last_post
which name_of_last_post is the name field from my GSON for the last post. This however just brings up the first page's posts again with their numbering starting at 25, I get that the numbering starts at 25 because count is set to 25. What I am asking is what is the format of the string I can create to get that next set of JSON items. you can try this your self by going to reddit.com/.json and taking that into a json editor and formatting it nicely than going to the next page of reddit and adding .json before the ?count=25&after=, you will see that the text following after= does not seem to appear on the first JSON file anywhere. If there are any parts of this question that are still unclear please leave a comment and I will check in on it later. Thanks and have a great day.
There are a couple of fields that you can use in order to fetch the next page on JSON.
You could either retrieve the 'name' of the last post, or instead of parsing the whole block, you can retrieve the last couple of fields from the JSON that reddit gives you. There are a couple of fields that you can easily use to navigate pages forwards and backwards, they're conveniently called 'after' and 'before'
Having that value, you can mount your URL with it, which in this case is http://www.reddit.com/.json?count=25&after=t3_3gi42o
This will get you a new JSON, with different 'after' and 'before' fields, pictured below:

Getting relational data faster with Parse

I'm using parse to get a number of places into a recyclerview.
The problem is it's quite slow, which probably has to do with my workflow.
In the RecyclerView I show: a picture, some textfields, tags, how many likes a place has, and how many comments.
For this I query my Place object, which has relations with a picture object (which holds a ParseFile), tag objects & comments object.
Getting 10 places like this takes about 10 seconds, this seems to be extremely show.
Worksflow:
in a AsyncTask I have a query to get all the Places.
I do a for loop on these places and per place I get the relations for the pictureUrls, tags & comments. (These are loaded into arraylists to pass to the adapter).
By the way, in the adapter the pictures are loaded with Picasso.
Any help on this would be appreciated :)
I solved it, for now.
What makes getting the placeobject slow is iterating over each object, getting the relation with picture object, tags & comments.
I dropped this iteration, instead I:
pictures
- I stored the url to the thumb in my place object, I load this picture with Picasso
comments
- I added a field "commentscount" and increment this everytime there is a one. I just needed the count, so this is enough. (I show the comments in the detailfragment)
tags
- I dropped the tags, and I will show them in the details too.
So, dirty fix maybe, but it might be just what this problem needed.. :)

android how to keep large List<String[]> while application runs

What is the best way to keep a List<String[]> while my application runs? I am having problems with my approach. It most of the time gives me an OutOfMemory Error since the list is too big.
The List<String[]> is the result of parsing a csv file that I have downloaded online. What I do is parse the csv in an activity then save its result in a static class member like:
String url = "http://xxx/pdf/pms/pms_test.csv";
try {
InputStream input = new URL(url).openStream();
CSVReader reader = new CSVReader(new InputStreamReader(input));
SchedController.sched = reader.readAll();
input.close();
}
...then access ClassName.sched on different activities.
I am doing this so that the parsed data will be available in every activity... And I don't have to parse again. What can I do to improve it?
I think you can have 2 approaches.
You save the file and parse it in a lazy loading way
You create a database and save your data.
I suggest you to create a database, this is not difficult and let you to manage well your data. You can do easily lazyLoading with cursor, or use a ORM (ORMLite / Greendao)... I think this is the best way and the fastest to load your data.
Hope this will help you.
Just to add to Paresh's comment.
I can suggest something similar I used in my app.
For example I need to display list of Items in a store. (Each item will have ID, name and cost).
To achieve this I first make a request to server to get number of items, say itemCount.
Now I set a limit to number of items displayed in a page say 100.
If the itemCount is greater than 100, I display an alert saying only 100 items will be displayed and a next button can be added to download next set of items.
Or if it is a search you can ask user to go back and refine the search.
If itemCount is less than 100 then you will not have any issues
This way Paging can be implemented to avoid OutOfMemory issues

better implementation of loading data to listview from parsed data

i have response for a news site which conatins more than 50 articles.so it is taking a lot of time to parse that and after parsing i am displaying it.As a result the user will be irritated .I want to display 1st 3 artivle as soon as it parse and while scrolling the list view it will fetch next 5 and show .I think in this way our response time will be reduced.plz suggest me any idea
You should use loading listview read the given tutorial fot inplementing it the url is that.
http://androidcore.com/android-programming-tutorials/466-progressively-loading-listviews.html
I hope you have solve your problem using it.

Categories

Resources