Setting Up the Loader 設定裝載機

來源:互聯網
上載者:User

You create a CursorLoader within a loader framework. To set up the framework, you implement theLoaderCallbacks<Cursor> as part of an Activity. In addition, to provide compatibility compatible with platform versions starting with Android 1.6, you must extend theActivity with the FragmentActivity class. http://blog.csdn.net/sergeycao

Note: A Fragment is not a prerequisite forCursorLoader. As a convenience, the support library classFragmentActivity contains the fragment and the loader frameworks, but they are completely independent of each other.

Before you can use the loader framework, you need to initialize it. To do this, retrieve aLoaderManager object and call its initLoader() method.

If you do use one or more Fragment objects in an Activity, the LoaderManager you retrieve is available to all of them.

Extend an Activity
To set up an Activity subclass to contain a CursorLoader, extend the subclass with must extend FragmentActivity, which provides the loader framework, and implement theLoaderCallbacks<Cursor> interface, which specifies method signatures that the loader framework uses to interact with theActivity.

For example:

public class DisplayActivity extends FragmentActivity
        implements LoaderManager.LoaderCallbacks<Cursor>
Retrieve a LoaderManager
To get an instance LoaderManager for use in your Activity, call FragmentActivity.getSupportLoaderManager() at the beginning of theonCreate() method. For example:

private LoaderManager mLoaderManager;
public void onCreate() {
...
mLoaderManager = this.getSupportLoaderManager();
Initialize the Loader Framework
Once you have the LoaderManager object, initialize it by callinginitLoader(). For example:

// CursorLoader instance identifier
public static final int URL_LOADER = 0;
...
// Initializes the CursorLoader
getSupportLoaderManager().initLoader(URL_LOADER, null, this);

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.