In my Android application I have one EditText, one Button, and one Listview. When I type a movie name into my EditText field and press on the Button, I want the ListView to be populated with movie names from the Rotten Tomatoes website that match what I entered into the EditText field.
But I can’t figure out how to use the Rotten Tomatoes JSON API to get the movie data. How do I do it?
Basically, you need to do four things:
http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=[your_api_key]&q=[search_keyword]&page_limit=[page_limit], as shown on this page.I’ve put together a small demo app that will do this. Please try out the code below.
MainActivity.java
res/layouts/activity_main.xml
And add this line to your
AndroidManifest.xml(it gives your Android app permission to use the Internet, which you obviously need to make the request to Rotten Tomatoes’ web server):Bonus answer:
If you want “live” search results as you type the search keyword into the EditText field, add a TextWatcher via EditText’s
addTextChangedListener()method, and make it do the HTTP request inonTextChanged().