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 there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Using an API to automatically populate a list in Android Studio

  • 23-11-2015 11:14pm
    #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, Registered Users 2 Posts: 2,763 ✭✭✭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, Registered Users 2 Posts: 11,264 ✭✭✭✭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, Registered Users 2 Posts: 6,262 ✭✭✭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,282 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