[英]Updating Cursor on SQLite database change
This is my scenario: 这是我的情况:
Activity 1 , Is where I have a list with items. 活动1 ,是我列出项目的地方。
Activity 1 contains an object of Class A , which deals with getting and returning a cursor of data retrieved by an SQLite database, via a Loader Manager set up, to Activity 1 . 活动1包含类A的对象,该对象处理通过设置的Loader Manager获取和返回由SQLite数据库检索到的数据的游标到活动1的情况 。
In Activity 1 , Each of these views within the list have buttons. 在活动1中 ,列表中的每个视图均具有按钮。 When pressing a button, Class B is executed. 当按下按钮时,将执行B类 。
Class B changes a single value within the SQLite database. B类在SQLite数据库中更改单个值。
In Class B , How can I notify the Loader Manager that the data has changed, for it to refresh the cursor. 在B类中 ,如何通知装载程序管理器数据已更改,以便刷新游标。 Remember, The Loader Manager is set up in Class A . 请记住,Loader Manager是在Class A中设置的 。
Essentially, If the above didn't make sense, I need to refresh the cursor as the underlying sql data has changed, but I need to do this from a class that has not a direct connection to the loader manager. 本质上,如果上述方法没有意义,则由于基础sql数据已更改,我需要刷新游标,但是我需要从与加载程序管理器没有直接连接的类进行此操作。
You can have both classes have access to each other , say in your onCreate in Activity1 您可以使两个类彼此访问,例如在Activity1中的onCreate中
ClassA obj1 = new ClassA(...);
ClassB obj2 = new ClassB(...);
obj2.setClasssA(obj1);
and inside your ClassB code, after you're done with updating the db you can just call a method in classA to update the cursor. 并且在您的ClassB代码内部,完成更新db后,您可以仅调用classA中的方法来更新游标。 something a long the line of : 东西很长的线:
obj1.onNewData();
I hope that makes sense 我希望这是有道理的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.