首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用引擎数据存储到Android listview

问应用引擎数据存储到Android listview
EN

Stack Overflow用户
提问于 2013-05-03 01:14:13
回答 1查看 639关注 0票数 2

我已经在App Engine后端设置了一个基本的实体类。

代码语言:javascript
复制
`@Entity`
`public class Club {`

  `@Id`
  `private int id;`
  `private String clubName;`

  `public Club() {`
  `}`

  `public int getId() {`
  `return id;`
  `}`

  `public void setId(int id){
      this.id =id;
   }`


  `public String getClubName() {
    return clubName;
  }`

  `public void setClubName(String clubName) {
  this.clubName = clubName;
  }
}`

我已经生成了云端点类并生成了云端点库。我希望能够将数据存储中的clubName填充到android中的列表视图中,但不确定如何做到这一点。我正在尝试遵循这个https://developers.google.com/appengine/docs/java/endpoints/consume_android,但是到目前为止我还不知道该怎么做。我是新手,如果有人能把我引向正确的方向,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2013-05-19 00:23:21

您可以使用以下步骤来实现您的目标:

1,正如google文档中提到的在android中使用云端点,通过添加所需的库并进行API调用来准备应用程序,然后从后端获取数据,您可以将这些数据存储到SQL数据库中。您可以在异步任务的onpostexecute方法中执行此步骤

代码语言:javascript
复制
protected void onPostExecute(ScoreCollection scores) {
// Do something with the result. maybe the store the data to sqlite database
}
}

要了解如何在SQLITe数据库中存储数据,请参阅http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html http://www.vogella.com/articles/AndroidSQLite/article.html

2,现在将数据从SQLITE db查询到cursor中,然后使用simplecursoradapter在布局或活动屏幕中的listview上显示来自光标的数据

一段大致的代码将包含如下步骤:

代码语言:javascript
复制
yourcursor = yourdatabase.query; //this is the cursor returned from querying your db
adapter = new SimpleCursorAdapter(this.getActivity(), R.layout.onerowinalistview,  yourcursor, FROM, TO,0); // this connects the columns of your DB mentioned in FROM array to the elements in a row of your list as mentioned in TO array
ListView yourlistview = (ListView) view.findViewById(R.id.yourlistview);//this is the listview element in your screen layout
yourlistview.setAdapter(adapter); // setting the adapter to the listview

希望这能有所帮助

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16343931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档