Android ListView how to populate with dynamic information retrieved from a google spreadsheet


I'm working on an android app that takes information from a google spreadsheet and puts in on a list view. However, I'm unable to come up with a solution for this. Any help would greatly be appreciated. For spreadsheet integration I use the Google Sheets API. I know client login is not secure, but this is just a test app for project purposes :)

Here is what my code looks like -

package com.bish.test; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.Toast; import android.app.Activity; import android.app.ProgressDialog; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.GridView; import android.widget.ListView; import android.widget.Toast; import com.google.gdata.client.authn.oauth.*; import com.google.gdata.client.spreadsheet.*; import com.google.gdata.data.*; import com.google.gdata.data.batch.*; import com.google.gdata.data.spreadsheet.*; import com.google.gdata.util.*; import java.io.IOException; import java.net.*; import java.util.*; public class MainActivity extends ActionBarActivity { SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration-v1"); String USERNAME = "cccc@gmail.com"; String PASSWORD = "xxx"; ListView list; String[] web; Integer[] imageId; CustomList adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); logIn(); try { refreshData(); } catch (IOException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } adapter = new CustomList(MainActivity.this, web, imageId); list=(ListView)findViewById(R.id.list); list.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } public void logIn() { final ProgressDialog ringProgressDialog = ProgressDialog.show(MainActivity.this, "Please wait ...", "Logging In...", true); ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { service.setUserCredentials(USERNAME, PASSWORD); Thread.sleep(2200); } catch (Exception e) { Toast.makeText(getApplicationContext(), "ERROR: Check your Internet Connection!", Toast.LENGTH_LONG).show(); e.printStackTrace(); System.exit(0); } ringProgressDialog.dismiss(); } }).start(); } public void refreshData() throws AuthenticationException, MalformedURLException, IOException, ServiceException { } }


I hope this will help you. This code:

1) Creates a new Spreadsheet

2) Inserts a new Worksheet

3) Inserts some values in the cells

4) Displays the values from the cells

import com.google.gdata.client.spreadsheet.FeedURLFactory; import com.google.gdata.data.spreadsheet.Cell; import com.google.gdata.data.spreadsheet.CellEntry; import com.google.gdata.data.spreadsheet.CellFeed; import com.google.gdata.data.spreadsheet.CustomElementCollection; import com.google.gdata.data.spreadsheet.ListEntry; import com.google.gdata.data.spreadsheet.ListFeed; import com.google.gdata.data.spreadsheet.SpreadsheetFeed; import com.google.gdata.data.spreadsheet.WorksheetEntry; import com.google.gdata.util.ServiceException; new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { final String SCOPE = "https://docs.google.com/feeds/default/private/full"; final String CREDENTIALS = sessionManager.getCredentials().getSelectedAccountName(); // CREATE A NEW GOOGLE SPREADSHEET WITH THE CORRESPONDING NAME SpreadsheetEntry newEntry = new SpreadsheetEntry(); newEntry.setTitle(new PlainTextConstruct(Constants.FILE_PREFIX + mFileName)); URL url = null; try { Log.d(TAG, "CRED: " + CREDENTIALS); url = new URL (SCOPE + "?xoauth_requestor_id=" + CREDENTIALS); // INSERT THE FILE spreadsheetService.insert(url, newEntry); } catch (MalformedURLException e) { Log.d(TAG, "MalformedURLException: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "IOException: " + e.getMessage()); } catch (ServiceException e) { Log.d(TAG, "ServiceException: " + e.getMessage()); } catch (IllegalArgumentException e) { // I RECEIVE MEDIA NOT SUPPORTED EXCEPTION, BUT THE FILE IS CREATED!!!! Log.d(TAG, "IllegalArgumentException: " + e.getMessage()); } catch (Exception e) { Log.d(TAG, "Exception: " + e.getMessage()); } try { // GET ALL THE FILES FROM THE USER'S GOOGLE DRIVE SpreadsheetFeed feed = spreadsheetService.getFeed( FeedURLFactory.getDefault() .getSpreadsheetsFeedUrl(), SpreadsheetFeed.class); // Creating the list of spreasheets in GDrive List<com.google.gdata.data.spreadsheet.SpreadsheetEntry> spreadsheets = feed.getEntries(); // parsing trough the feed entries for (int i = 0; i < spreadsheets.size(); i++) { com.google.gdata.data.spreadsheet.SpreadsheetEntry e = (com.google.gdata.data.spreadsheet.SpreadsheetEntry) spreadsheets.get(i); // IF WE LOCATE THE FILE BASED ON THE FILENAME if( e.getTitle().getPlainText().equals(Constants.FILE_PREFIX + mFileName)) { Log.d(TAG, "ENTRY: " + e.getTitle().getPlainText()); URL worksheetFeedUrl = e.getWorksheetFeedUrl(); Log.d(TAG, "worksheetFeedUrl: " + worksheetFeedUrl); // The first time this feed is used to create the new worksheet WorksheetFeed worksheetFeed = spreadsheetService.getFeed (worksheetFeedUrl, WorksheetFeed.class); Log.d(TAG, "worksheetFeed OK !"); // Create the second worksheet WorksheetEntry newWorksheet = new WorksheetEntry(15, 5); newWorksheet.setTitle(new PlainTextConstruct("Sheet2")); worksheetFeed.insert(newWorksheet); // The second time this feed is used to get the worksheets worksheetFeed = spreadsheetService.getFeed (worksheetFeedUrl, WorksheetFeed.class); // Get the first worksheet and insert the titles List <WorksheetEntry> worksheetEntrys = worksheetFeed.getEntries (); WorksheetEntry sheet1 = worksheetEntrys.get(0); WorksheetEntry sheet2 = worksheetEntrys.get(1); URL sheet1CellFeedUrl = sheet1.getCellFeedUrl (); CellFeed sheet1CellFeed = spreadsheetService.getFeed (sheet1CellFeedUrl, CellFeed.class); sheet1CellFeed.insert (new CellEntry (1, 1, getResources().getString(R.string.cell_title_name))); sheet1CellFeed.insert (new CellEntry (1, 2, getResources().getString(R.string.cell_title_description))); sheet1CellFeed.insert (new CellEntry (3, 2, getResources().getString(R.string.some_string))); sheet1CellFeed.insert (new CellEntry (13, 2, "=COUNTIF(Sheet1!F2:F,B3)")); sheet1CellFeed.insert (new CellEntry (14, 2, "=B9 - TODAY()")); // GET THE CONTENT FROM THE CELLS FROM THE SECOND WORKSHEET URL sheet2CellFeedUrl = sheet2.getCellFeedUrl (); CellFeed sheet2CellFeed = spreadsheetService.getFeed (sheet2CellFeedUrl, CellFeed.class); List<CellEntry> cellEntryList = sheet2CellFeed.getEntries(); if(cellEntryList != null && !cellEntryList.isEmpty()) { for (CellEntry cellEntry : cellEntryList) { Cell cell = cellEntry.getCell(); Log.d(TAG, "VALUE:" + cell.getValue()); } } break; } } } catch (Exception e) { Log.d(TAG, "Exception: " + e.getMessage()); runOnUiThread(new Runnable() { @Override public void run() { showMessage("Error!"); } }); } return null; } }.execute();


  • onDraw() Method work only when i creating my object in the onDraw()
  • Editing text in action bar
  • ListView repeating the data on load more
  • SearchView wrong alignment
  • Android RecyclerView Blank Space
  • List view crashes when scrolling “The application may be doing too much work on its main thread.”
  • Listview with multiple strings
  • OnItemSelectedListener for Spinner that was added programmatically does not trigger
  • Is it safe to accept URL parameters for populating the `url_for` method?
  • calling a fragment from fragment
  • Activity overlaying. WindowManager.LayoutParams
  • Syntax error on tokens, AnnotationName expected instead - error on query
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Implementing “partial void” in VB
  • Sending HTML Form Data to Spring REST Web Service
  • Ember.js model to be organised as a tree structure
  • ListItem.Attributes.Add not working
  • Bypass multiple inheritance in Java
  • How does document.ready work with angular element directives?
  • wxPython: displaying multiple widgets in same frame
  • How can I extract results of aggregate queries in slick?
  • OOP Javascript - Is “get property” method necessary?
  • Paperclip, set path outside of rails root folder
  • Deleting and Updating values from a cusrsor adapter
  • PHP - How to update data to MySQL when click a radio button
  • Window Size for Mac application
  • what is the difference between the asp.net mvc application and asp.net web application
  • jquery mobile loadPage not working
  • php design question - will a Helper help here?
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How to stop GridView from loading again when I press back button?
  • Bitwise OR returns boolean when one of operands is nil
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How do I use LINQ to get all the Items that have a particular SubItem?