@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if ((cursor.moveToFirst()) && (cursor.getCount() == 1)) { // Check to see if there is a no artists flag in the cursor indicating that // there are no artists for the given search term. String flag = cursor.getString(COL_ARTIST_SPOTIFY_ID); if (flag.equals(DataContract.ArtistEntry.FLAG_NO_ARTISTS_FOUND)) { Toast toast = Toast.makeText( getActivity(), getString(R.string.toast_no_artist_found), Toast.LENGTH_LONG); toast.show(); } else { mArtistsAdapter.swapCursor(cursor); } } else if (cursor.moveToFirst()) { Log.i( TAG, "onLoadFinished called and cursor.moveToFirst() is true. mArtistAdapter swaps with cursor"); mArtistsAdapter.swapCursor(cursor); if (mPosition != ListView.INVALID_POSITION) { mListView.smoothScrollToPosition(mPosition); } } else if (null != mSearchTerm) { // if the cursor is null, this means that the artists for mSearchTerm have // not been added to the db. Log.i( TAG, "onLoadFinished called, cursor is empty, and mSearchTerm is " + mSearchTerm + ". getArtists() called to start new FetchArtistsTask"); getArtists(); } }
@Override public void onLoaderReset(Loader<Cursor> loader) { Log.i(TAG, "onLoadReset called mArtistsAdapter is swaps with null"); mArtistsAdapter.swapCursor(null); }