This is my app architecture so far:
I have a MainActivity which has a Fragment which has an Adapter:
Activity > Fragment > Adapter
I update my SQLiteDb from my Activity, I would like to know how I can call the method:
adapter.notifySetDataChange();
from there (or from my DatabaseHandler Class) DatabaseHandler is just a class that I can create anywhere and retrieve my SQLiteDB.
I guess this might be a suitable use case for the observer pattern, but I'm not quite sure how I can go about it.
我建议使用游标加载器模式,该模式将自动更新适配器: http : //developer.android.com/training/load-data-background/setup-loader.html
You can expose a public method (eg updateMyAdapter()
) in your fragment that updates your adapter and call it from your activity. You can get the fragment from your activity using
YourFragment f = (YourFragment)getFragmentManager().findFragmentById(...);
if(f != null)
f.updateMyAdapter();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.