Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
749 views
in Technique[技术] by (71.8m points)

android - How to get LoaderManager in a ListActivity

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...