如何使用谷歌应用程序引擎从数据存储中检索信息并使用java在Android应用程序的列表视图中显示它?

发布于 2025-01-03 08:50:32 字数 2242 浏览 1 评论 0原文

我正在尝试制作一个 Android 应用程序,它从 Google 应用程序引擎数据存储中检索信息并将其显示为 Android 应用程序中的列表视图。任何人都可以帮助我编写一些代码或解释为此目的到底需要做什么?我已经在服务器端进行了修改以将数据存储在数据存储上..我不知道如何将该数据获取到android应用程序中..我正在使用eclipse indigo并且语言是java

编辑:我将我的代码我用来从数据存储中检索一组字符串并将其放入列表视图中...代码看起来很混乱,但我请求您耐心等待并解释如何准确地编写它..目前该应用程序是强制的- 每当我到达时就关闭应该显示检索到的字符串列表的页面...

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;
    }
}    '

注意:TrialDB 是包含我想要存储在数据存储上的所有字段的文件。 displaylayout 是我在其中创建列表视图的 xml 文件。 我猜测我必须放置用于显示内容的代码的主要部分是在 onCreate() 方法中。 请帮忙!

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 !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汹涌人海 2025-01-10 08:50:32

这已经是学习 Google App Engine 和 Android 开发的一个非常好的起点

我可能会编写要遵循的步骤

  1. 编写一个 Google App Engine 应用程序从数据存储区读取数据并以 JSON 形式给出。您可以使用 GAE Web 框架,或者 Django。完成此操作后,您将获得一个网址,可在浏览器中提供您的数据。
  2. 编写Android 的 hello world 应用程序。这一步让您有机会了解和设置 Android 开发环境。
  3. 编写一个使用带有静态数据的列表视图的 Android 应用程序。
  4. 通过从网络调用单个简单网址来扩展您的 Android 应用,然后将其打印到屏幕上。
  5. 通过在应用内调用 Google App Engine 应用程序网址来扩展您的应用程序。现在您的应用程序中已经有了数据存储区数据。
  6. 用您的数据填充您的列表视图。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文