Shanky
Shanky

Reputation: 15

how to retrieve info from datastore using google app engine and display it in a list view on an android app using java?

I am trying to make an android app that retrieves info from google app engine datastore and display it as a listview in the android app..can anyone help me out with some code or explain what exactly needs to be done for this purpose? i have already made modifications on the server side to store data on the datastore..what i dont know is how to get that data onto the android app..i am using eclipse indigo and language is java

EDIT : I am putting my code that i am using to retrieve a set of strings from datastore and put it in a list view...the code is gonna look all haywire but i request you to bear with me and explain how exactly to write it..presently the application is force-closing whenever i get to the page where this list of retrieved strings is supposed to be displayed...

public class Display extends ListActivity
{

    private LayoutInflater mInflater;
    private Vector<RowData> data;
RowData rd;

static String[] title;
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.displaylayout);


    MyRequestFactory factory = (MyRequestFactory)Util.getRequestFactory(Display.this,MyRequestFactory.class);
    FebfourthRequest febfourthRequest = factory.febfourthRequest();
    final List<TrialDBProxy> list= new ArrayList<TrialDBProxy>();
       febfourthRequest.queryTrialDBs().fire(new Receiver<List<TrialDBProxy>>() 
    {

        @Override
        public void onSuccess(List<TrialDBProxy> arg0) {
            // TODO Auto-generated method stub
            list.addAll(arg0);
        }   


    });


    for(int i=0;i<list.size();i++)
    {
        title[i] = list.get(i).getMessage();
    }

    mInflater = (LayoutInflater) getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    data = new Vector<RowData>();

    for(int i=0;i<title.length;i++)
    {
        rd = new RowData(i,title[i]);
        data.add(rd);
    }
    int[] to = new int[] { R.id.text1, R.id.text2 };

    @SuppressWarnings("deprecation")
    Cursor mCursor = this.getContentResolver().query(People.CONTENT_URI, null,      null, null, null);
    ListAdapter adapter = new       SimpleCursorAdapter(this,R.layout.displaylayout,mCursor,title,to);
    setListAdapter(adapter);
    getListView().setTextFilterEnabled(true);

}
private class RowData 
{
protected int mId;
protected String mTitle;

RowData(int id,String title)
{
mId=id;
mTitle = title;

}
    @Override
    public String toString() 
    {
        return mId+" "+mTitle;
    }
}    '

NOTE : TrialDB is the file that contains all my fields that i want to store on the datastore. displaylayout is the xml file where i have created a listview. i am guessing the main part where i have to put code for displaying stuff is in the onCreate() method. PLEASE HELP !

Upvotes: 0

Views: 1109

Answers (1)

Samet Atdag
Samet Atdag

Reputation: 992

This is already a very good starting point for learning both Google App Engine and Android Development.

I may write the steps to follow:

  1. Write a Google App Engine application which reads data from datastore and gives as JSON. You can use GAE web framework, or maybe Django. After doing that, you will have a url which gives you your data in your browser.
  2. Write a hello world application for Android. This step gives you an opportunity to understand and setup Android development environment.
  3. Write an Android app which uses a listview with static data.
  4. Extend your Android app with calling a single simple url from web, then print it on your screen.
  5. Extend your application via calling your Google App Engine application url inside your app. Now you have your datastore data in your app.
  6. Populate your listview with your data.

Upvotes: 2

Related Questions