Android - SwipeRefreshLayout example (an Android Material Design UI Pattern)

    One of the great ideas formalized in the new Material Design user interface guidelines is the Swipe to Refresh UI pattern. In fact, you’ve probably already seen and used it. It’s found its way into many popular Android apps like Facebook, Google Newsstand, Trello, Gmail and many others.

    SwipeRefreshLayout is very useful when we work with data from Internet or Server. With a simple action, we'll update data.
    In this post, I present a simple project that:
- Get JSON data from an URL.
- Parse JSON and populating data to a ListView.
- Swipe to refresh/ update data.

1. Lauch Eclipse and start a new Android Project (min-sdk is 14).
2. Create a model object for our project (
3. Create layout for launching activity (activity_swipe.xml):
4. Give a Custom AsyncTask to get data from Internet through an URL like this:
5. In SwipeActivity, we must:
- set OnRefreshListener for SwipeRefreshLayout.
- execute AsyncTask and get data after it's done.
- set/notify adapter for ListView.
Full code:
6. Okey, these are some necessary class/ layout in project:
- A custom Adapter for ListView:
- Layout for each ListView row(item_listview.xml):
- Some own colors use in projects (res/values/colors.xml):
7. Some result screens:

pic name pic name pic name
(Sorry for having ads)


Previous post
« Prev Post
Next post
Next Post »