如何在 ListActivity 中获取 LoaderManager
我正在使用兼容性包来实现 API 级别 < 的 CursorLoader 11 根据 doc 和此 答案 和这个精彩的教程,我已经导入了支持包并实现了LoaderManager.LoaderCallbacks,但接下来我必须调用:
getSupportLoaderManager()
为此必须扩展 FragmentActivity,然后从 Activity Context 调用,但我已经扩展了 ListActivity,并且想要进行静态调用来获取LoaderManager,像这样:
FragmentActivity.getSupportLoaderManager()
显然,这是一种获取 LoaderManager < 11、医生是这么说的:
要管理片段和加载器,您必须使用 FragmentActivity.getSupportFragmentManager() 和 FragmentActivity.getSupportLoaderManager() 方法(而不是 getFragmentManager() 和 getLoaderManager() 方法)。
但它给出了这个编译时错误:
Cannot make a static call to a non-static method
FragmentActivity 的代码, getSupportLoaderManager() 在这里不是静态的,这解释了错误,但为什么文档是这样的显示静态调用...我现在很困惑...
请帮忙!
I am using compatibility package for implementing CursorLoader in API level < 11
As per the doc and this answer and this wonderful tutorial, I have imported the support packages and implemented the LoaderManager.LoaderCallbacks, but next I have to call:
getSupportLoaderManager()
and for that one has to extend FragmentActivity, and then call from Activity Context, but I have already extended ListActivity, and want to make a static call to get LoaderManager, like this:
FragmentActivity.getSupportLoaderManager()
Apparently, this is a way to get LoaderManager < 11, that's what the doc says:
To manage your fragments and loaders, you must use the methods FragmentActivity.getSupportFragmentManager() and FragmentActivity.getSupportLoaderManager() (instead of the getFragmentManager() and getLoaderManager() methods).
But it is giving this compile time error:
Cannot make a static call to a non-static method
Code for FragmentActivity, getSupportLoaderManager() is not static here, that explains the error, but why is the Doc showing a static call...i am confused now...
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您扩展
FragmentActivity
,则只能使用 Android 兼容性库中的Loader
框架。考虑将ListActivity
转换为ListFragment
和FragmentActivity
。You can only use the
Loader
framework from the Android Compatibility Library if you extendFragmentActivity
. Consider converting yourListActivity
into aListFragment
and aFragmentActivity
.