我正在实现一个ListView,它包含一个带有LoaderCallbacks的Customized CursorAdpater。当调用OnCreatLoader时,我正在运行AsyncTaskLoader,它从数据库中获取theCursor。我注意到在加载游标后调用swapCursor时会有延迟。有没有解决方案,比如一次加载10个项目?如果是这样,我在哪里可以做到这一点?
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args)
{
// Create the Cursor that will take care of the data being displayed
Log.d("TAG", "onCreateLoader...");
return new MessageAsyncTaskLoader(getActivity());
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor)
{
// Now Bind the data to the View
Log.d("TAG", "onLoadFinished...ARG1= " + cursor);
mCusrorAdapter.swapCursor(cursor);// This is were the delay is...
}
public static class MessageAsyncTaskLoader extends AsyncTaskLoader<Cursor>
{
Cursor cursor;
public MessageAsyncTaskLoader(Context context)
{
super(context);
}
@Override
protected void onStartLoading()
{
super.onStartLoading();
mCusrorAdapter = new CustomCursorAdapter(mContext);
mListView.setAdapter(mCusrorAdapter);
forceLoad();
}
@Override
public Cursor loadInBackground()
{
cursor = mContext.getContentResolver().query(CONTENT_URI, null, null,null,
DataBase.COLUMN_MESSAGE_DATE+ " DESC");
return cursor;
}
@Override
protected void onStopLoading()
{
super.onStopLoading();
cursor.close();
}
}