Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Using an API to automatically populate a list in Android Studio

Options
  • 24-11-2015 12:14am
    #1
    Closed Accounts Posts: 789 ✭✭✭


    Hey lads,

    I'm currently doing a project for college that should display the top 50 books on Good Reads. I received an API key from them but honestly have no clue how to populate the list using this API.

    Any help would be greatly appreciated.


Comments

  • Registered Users Posts: 2,762 ✭✭✭Sheeps


    A little more information about what you're trying to do? Are you trying to populate a list view in android sdk? Have you read the api documentation? It looks like it's just an HTTP XML based api. Get familiar with how to use something like the android http client. Then get an example online of a of a get request. Put the two together.

    Then you get a http response look at how you can parse it. Look at how you can use an XML parser to get the data from the response. Then you're going to need to find out how to modify your list item with the relevant text. Look at list adapters. Is it just a text view?

    Answer these questions and you're on your way to getting started.


  • Registered Users Posts: 11,262 ✭✭✭✭jester77


    Are you allowed to use 3rd party libs? Retrofit is excellent, it's a type safe http client that makes network configuration and handling very easy.

    To add data to a list, look at RecyclerView and how data is managed with the the Adapter and ViewHolder.


  • Registered Users Posts: 6,250 ✭✭✭Buford T Justice


    Have they provided documentation for running queries against their API?

    EDIT: They have some documentation here

    But in a nutshell, you submit a query via browser link including your API key, and the service will return an XML response which you can parse however you see fit.


  • Closed Accounts Posts: 789 ✭✭✭Fakman87


    Thanks very much for the help lads!

    I'm in over my head here. This is the code I have for the listview currently:

    public class BookActivity extends AppCompatActivity {
    ListView listView;
    ArrayAdapter<String> adapter;
    String[] books = {"1984",
    "The Great Gatsby",
    "The Catcher in the Rye",
    "Harry Potter and the Sorcerer's Stone",
    "The Hobbit"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_book);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    listView = (ListView)findViewById(R.id.list_view);
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,books);
    listView.setAdapter(adapter);

    I'm adding those strings manually there but totally lost with the API business :P


  • Moderators, Computer Games Moderators Posts: 4,281 Mod ✭✭✭✭deconduo


    Fakman87 wrote: »
    Thanks very much for the help lads!

    I'm in over my head here. This is the code I have for the listview currently:

    public class BookActivity extends AppCompatActivity {
    ListView listView;
    ArrayAdapter<String> adapter;
    String[] books = {"1984",
    "The Great Gatsby",
    "The Catcher in the Rye",
    "Harry Potter and the Sorcerer's Stone",
    "The Hobbit"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_book);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    listView = (ListView)findViewById(R.id.list_view);
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,books);
    listView.setAdapter(adapter);

    I'm adding those strings manually there but totally lost with the API business :P

    A simple view of web APIs is that you call a particular URL and you get a page with data, usually in XML or JSON format. For Goodreads an example (from the API documentation) is:
    https://www.goodreads.com/search.xml?key=YOUR_KEY&q=Ender%27s+Game
    

    If you go to that URL replacing YOUR_KEY with the actual API key you have, you should get a list of books related to Ender's Game (the search term in the URL).

    The full list of API methods are documented here:
    http://www.goodreads.com/api/index


  • Advertisement
  • Closed Accounts Posts: 789 ✭✭✭Fakman87


    That's great thanks I'll try that now :)


Advertisement