How to get LoaderManager in a ListActivity

与世无争的帅哥 提交于 2019-11-28 11:36:23

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/7834647/how-to-get-loadermanager-in-a-listactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!