2

我在App Engine后端设置了一个基本的实体类。应用引擎数据存储到Android列表视图

`@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; 
    } 
}` 

我生成了云端点类并生成了云端点库。 我想能够从数据存储到Android的ListView填充clubName,但不知道如何做到这一点。 我正在尝试关注https://developers.google.com/appengine/docs/java/endpoints/consume_android,但至今我无法理解要做什么。我是新来的,如果有人让我朝着正确的方向,那将是非常棒的。通过添加所需的库

1,正如谷歌文档在机器人,准备您的应用程序消耗的云终端提及并进行API调用,然后得到:

回答

2

您可以使用下面的步骤来实现你的目标来自后端的数据,您可以将该数据存储到SQL数据库中。你能做到这一步在非同步任务的onpostexecute方法

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数据库的数据为cursor然后使用simplecursoradapter在布局或活动屏幕中显示listview上的光标数据

大致的一段代码将具有如下步骤:

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 

希望这会有所帮助

相关问题