Build a Blog Reader Android App
The Blog Reader app will teach us one of the most common and important uses of an Android app: downloading data from the Internet and displaying it in a list. We will investigate the Model-View-Controller design pattern that is essential for all Android apps, learn how to request data from the web, parse and use information in JSON format, and utilize the built-in Android ListActivity and adapter. We'll also see how to display a webpage inside our app.
Watch the Trailer
5 badges • 24 videos
Exploring the Master-Detail Template
Included in Eclipse are a few Android project templates that can help us get started quickly with certain types of apps. In this stage we'll learn how the Master-Detail Template works, and we'll talk about the Model-View-Controller design pattern that is behind many Android applications.
Rebuilding from Scratch
Using templates is great for getting started quickly, but to truly understand how to build something we should do it from scratch. In this stage we'll start with a blank project and use the Android system components for displaying data in a list. We'll see first-hand how to build the components of the Model-View-Controller pattern we talked about in the last stage.
Getting Data from the Web
Now that we're comfortable displaying simple data in a ListView, let's take a look at how to connect to a website and request some data. This stage will cover how to establish that kind of connection and then use an AsyncTask in a separate thread of execution to retrieve data. We'll also see how to parse through the JSON data returned from the blog, and along the way we'll cover Java Exceptions and how to detect and handle them.
Adapting Data for Display in a List
Now that we've connected to the Treehouse Blog and retrieved data in JSON format, let's take a look at how to adapt that data for display in our ListView. We'll first adapt titles using an ArrayAdapter, we'll add some code to manage the user interface while our web request is running, add an AlertDialog in case of errors, and then we'll add author information using a more complex adapter called SimpleAdapter.
Using Intents to Display and Share Posts
Our list of blog posts looks nice and everything is working well behind the scenes, but nothing happens when the user taps on an item in the list. In this stage we'll add a listener for such a tap using the 'onListItemClick()' method and talk about a few different Intents we can use for different actions. First, we'll use an Intent to open the URL of the post in the browser, but then we'll add a second Activity to open the URL within our app and display it in a WebView. Finally we'll let users easily share the link however they want using the simple Share Intent.