我已经在App Engine后端设置了一个基本的实体类。
`@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,但是到目前为止我还不知道该怎么做。我是新手,如果有人能把我引向正确的方向,我将不胜感激。
发布于 2013-05-19 00:23:21
您可以使用以下步骤来实现您的目标:
1,正如google文档中提到的在android中使用云端点,通过添加所需的库并进行API调用来准备应用程序,然后从后端获取数据,您可以将这些数据存储到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 db查询到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希望这能有所帮助
https://stackoverflow.com/questions/16343931
复制相似问题