如何获得LoaderManager在ListActivity [英] How to get LoaderManager in a ListActivity
问题描述
我使用在API级别和LT实施CursorLoader兼容包; 11 由于每 DOC 这<一href="http://stackoverflow.com/questions/7833860/implementation-of-cursorloader-for-api-level-11/7834023#7834023">answer这美妙的教程,我已导入的支持包和实施 LoaderManager.LoaderCallbacks ,但下次我必须调用:
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()
和一个具有扩展FragmentActivity,然后从活动上下文打电话,但我已经扩展ListActivity,并希望做一个静态调用得到LoaderManager,像这样的:
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()
显然,这是一种方式来获得 LoaderManager &LT; 11,这正是医生说:
Apparently, this is a way to get LoaderManager < 11, that's what the doc says:
要管理你的碎片和装载机,必须使用方法FragmentActivity.getSupportFragmentManager()和FragmentActivity.getSupportLoaderManager()(而不是getFragmentManager()和getLoaderManager()方法)。
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
<一个href="http://$c$c.google.com/p/android-eksempler/source/browse/trunk/Android30Elementer/src/android/support/v4/app/FragmentActivity.java?r=50"相对=nofollow> code 为FragmentActivity,getSupportLoaderManager()不是静态的在这里,这解释了错误,但为什么是文档显示静态调用...我很困惑,现在...
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...
请帮忙!
推荐答案
您只能使用从Android兼容性库的装载机
框架,如果你扩展 FragmentActivity
。考虑把你的 ListActivity
到 ListFragment
和 FragmentActivity
。
You can only use the Loader
framework from the Android Compatibility Library if you extend FragmentActivity
. Consider converting your ListActivity
into a ListFragment
and a FragmentActivity
.
这篇关于如何获得LoaderManager在ListActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!