开发者

Android + Use LoaderManager with an ArrayAdapter?

I might be way off here, but I have an ArrayAdapter managing static data for a ListFragment. Very sim开发者_运维问答ple stuff. However, I'm interested in taking advantage of the new LoaderManager class. Can I still use my ArrayAdapter and write my own loader? The documents seem to suggest this is true:

"...the most common use of this is with a CursorLoader, however applications are free to write their own loaders for loading other types of data."

If this is the case, how might I work with the overridden LoaderManager.LoaderCallbacks interface methods?

@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {return null;}

@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {}

@Override
public void onLoaderReset(Loader<Cursor> arg0) {}


If you are creating a new type of Loader you might need to use a different type for the data rather than Cursor (unless your new loader also returns Cursors).

Your callbacks should look something like

@Override
public Loader<MyDataType> onCreateLoader(int id, Bundle args) {
    return new MyCustomLoader(...);
}

@Override
public void onLoadFinished(Loader<MyDataType> loader, MyDataType data) {
    myArrayAdapter.add(data.something()); // etc
}

@Override
public void onLoaderReset(Loader<MyDataType> loader) {
     myArrayAdapter.clear();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜