1

I am just starting android and I have a quick question with sqlite db.

i created a db with a couple of columns but am now withdrawing just one column from that. I was wondering if I should withdraw that column into an array of strings, then populate it into a listview, or directly put it into an adapter of sorts (which i am starting to read about).

also, if i open up a new activity, and change the information of some item (deleting or inserting), then go back to this same activity, would it automatically update or would i have to override onstart()

4

3 回答 3

1

在 Android 中从数据库填充 UI 的最佳方式是使用CursorLoader. 尝试阅读此处的开发指南

基本上,您实现LoaderManager.Callbacks, 和onCreate, 查询数据库并将响应传递给加载程序。

于 2013-08-25T07:25:12.403 回答
0

首先从 db 调用一个返回 Cursor 的函数

 Cursor cursor = dbhelper.Function();

然后使用一个字符串数组

String [] from = new String [] {
        Dbadapter.KEY_NAME
} 

然后使用一个 int 数组来分配它

  Int []  to = new int []  {
        R.id.textview1
 } 

然后设置适配器

 SimpleCursorAdapter sca = new SimpleCursorAdapter ( this, R.layout.listview, cursor, from, to, 0);
于 2013-08-25T04:10:50.710 回答
-3

最好为此覆盖 onResume(),因为每次更新并返回应用时,onResume() 都会收到回调(请参阅Android 生命周期活动)。只有在这里您可以获取该列的记录并将其添加到列表中。

欢迎来到安卓开发!一切顺利!

于 2013-08-25T07:19:12.597 回答