How to connect an Android app to an API and display data in a list?

12,152

Solution 1

Try the Marakana tutorials. It's a set of complete video tutorials on Youtube. JSON parsing has been explained with a Twitter timeline example. I have forgotten the video number of that specific tutorial, but with a little fiddling you will surely find it.

Link to first tutorial:

http://www.youtube.com/watch?v=5RHtKIo_KDI

Solution 2

I would like to recommence to use Retrofit. Less code and get better performance. http://square.github.io/retrofit/

You can find many code examples and support.

You can just define your API in Interface

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

And set the main URL of your API

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com/")
    .build();

GitHubService service = retrofit.create(GitHubService.class);

Final step, Retrofit will convert the response Json to correct Collection

Call<List<Repo>> repos = service.listRepos("octocat");
Share:
12,152
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I am trying to make an app that connects to an API (via URL) to retrieve sessions of past workshops. The API returns all data in JSON format. I've tried to do a couple of tutorials (using twitter API's) but they are not working. Here is a link to the tutorial: http://www.vogella.com/articles/AndroidJSON/article.html

    Any help?