CursorLoader
A loader that queries the ContentResolver
and returns a Cursor. This class implements the Loader protocol in a standard
way for querying cursors, building on AsyncTaskLoader to perform the cursor
query on a background thread so that it does not block the application's UI.
A CursorLoader must be built with the full information for the query to perform, either through the CursorLoader(Context, Uri, String[], String, String[], String) or creating an empty instance with CursorLoader(Context) and filling in the desired paramters with setUri(Uri), setSelection(String), setSelectionArgs(String[]), setSortOrder(String), andsetProjection(String[]).
LoaderCallbacks
Callback interface for a client to interact with the manager.
public class MuiscList extends Activity implements LoaderCallbacks<Cursor>{
@Override
protected void onCreate(Bundle savedInstanceState) {
LOG.i(CLASSNAME,"onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_muisc_list);
ListView listViewTmp = (ListView)findViewById(R.id.listView1);
mCursorAdapter = new CustomCursorAdapter(this);
listViewTmp.setAdapter(mCursorAdapter);
// Initializes the CursorLoader
getLoaderManager().initLoader(AUDIO_LOADER, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int loaderID, Bundle bundle) {
LOG.i(CLASSNAME,"onCreateLoader loaderID : "+loaderID);
switch (loaderID) {
case AUDIO_LOADER:
CursorLoader tmp = new CursorLoader(
this, // Context
audioExternalUri, // Table to query
null, // Projection to return
null, // No selection clause
null, // No selection arguments
null // Default sort order
);
if(null==tmp){
LOG.i(CLASSNAME,"tmp is null");
}
return tmp;
default:
LOG.i(CLASSNAME,"onCreateLoader default");
return null;
}
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor returnCursor) {
LOG.i(CLASSNAME,"onLoadFinished");
mCursorAdapter.swapCursor(returnCursor);
LOG.i(CLASSNAME,"cursorAdapter.getCount() : "+mCursorAdapter.getCount());
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
LOG.i(CLASSNAME,"onLoaderReset");
mCursorAdapter.swapCursor(null);
}
'PROGRAMING > Android' 카테고리의 다른 글
listView 항목에 Audio Albumart(thumbnail)을 지연 없이 나타내기.AsyncTask (1) | 2013.02.22 |
---|---|
Audio AlbumArt 가져오기. (0) | 2013.02.22 |
[widget]android.widget.CursorAdapter, ViewHolder pattern (0) | 2013.02.19 |
android.database.Cursor 와 ContentProvider[Uri] (0) | 2013.02.18 |
[widget]android.widget.ListView [3] convertView 사용과 Holder Pattern (0) | 2013.02.18 |