/** {@inheritDoc} */
  public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    if (getActivity() == null || cursor == null) {
      return;
    }

    mCursor = cursor;
    getActivity().startManagingCursor(mCursor);

    // If there was a last-opened track, load it. Otherwise load the first track.
    cursor.moveToFirst();
    String lastTrackID = UIUtils.getLastUsedTrackID(getActivity());
    if (lastTrackID != null) {
      while (!cursor.isAfterLast()) {
        if (lastTrackID.equals(cursor.getString(TracksAdapter.TracksQuery.TRACK_ID))) {
          break;
        }
        cursor.moveToNext();
      }

      if (cursor.isAfterLast()) {
        loadTrack(null, mAutoloadTarget);
      } else {
        loadTrack(cursor, mAutoloadTarget);
      }
    } else {
      loadTrack(null, mAutoloadTarget);
    }

    mAdapter.setHasAllItem(true);
    mAdapter.setIsSessions(TracksFragment.NEXT_TYPE_SESSIONS.equals(mNextType));
    mAdapter.changeCursor(mCursor);
  }
  /** {@inheritDoc} */
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    final Cursor cursor = (Cursor) mAdapter.getItem(position);
    loadTrack(cursor, true);

    if (cursor != null) {
      UIUtils.setLastUsedTrackID(
          getActivity(), cursor.getString(TracksAdapter.TracksQuery.TRACK_ID));
    } else {
      UIUtils.setLastUsedTrackID(getActivity(), ScheduleContract.Tracks.ALL_TRACK_ID);
    }

    if (mListPopupWindow != null) {
      mListPopupWindow.dismiss();
    }
  }