Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何根据在其他活动中收集的信息更新listview?_Android_Listview_Android Adapter - Fatal编程技术网

Android 如何根据在其他活动中收集的信息更新listview?

Android 如何根据在其他活动中收集的信息更新listview?,android,listview,android-adapter,Android,Listview,Android Adapter,我目前有一个简单的活动,它有一个按钮来创建注释。单击该按钮时,会激发转到另一个活动的意图,该活动是该注释中所需信息的模板 保存模板中的信息、关闭该活动并用模板信息填充初始活动列表视图的最佳方法是什么 如果我打算创建一个SQLite数据库来与NoteListView项目交互,我是否需要一个内容提供者 What is the best way to hold onto the information [...] and populate the initial activities listview

我目前有一个简单的活动,它有一个按钮来创建注释。单击该按钮时,会激发转到另一个活动的意图,该活动是该注释中所需信息的模板

保存模板中的信息、关闭该活动并用模板信息填充初始活动列表视图的最佳方法是什么

如果我打算创建一个SQLite数据库来与NoteListView项目交互,我是否需要一个内容提供者

What is the best way to hold onto the information [...] and populate the initial activities listview with the template information?
我建议使用SQLite数据库

Will I need a content provider?
这不是必需的。内容提供商通常用于向其他应用程序共享信息

简单地说

1-创建一个类,在其中扩展
SQLiteOpenHelper
。从这里可以控制数据库周期

2-创建一个管理上述类的类,并对数据库进行读/写操作。我可能会使这个类中的所有方法
都是静态的
,这样就可以从不同的活动中访问它们,而不必一直实例化

然后,一旦用户创建了一个新的便笺,并点击了一个“保存”按钮,您就可以调用Manager类将新的便笺数据存储在数据库中。恢复初始活动(承载ListView的活动)后,只需更新用于填充ListView的光标即可

请确保您正在使用游标适配器

对于一个简单的示例,您可以看到以下两个类:(注意:类方法中的注释是西班牙语)