Code example for ListFragment

Methods: getListView, getActivity, getView

0
    } 
 
 
    /** {@inheritDoc} */ 
    public void onQueryComplete(int token, Object cookie, Cursor cursor) {
        if (getActivity() == null) {
            return; 
        } 
 
        if (token == VendorsQuery._TOKEN) {
            onVendorsOrSearchQueryComplete(cursor);
        } else if (token == TracksQuery._TOKEN) {
            onTrackQueryComplete(cursor);
        } else { 
            cursor.close();
        } 
    } 
 
    /** 
     * Handle {@link VendorsQuery} {@link Cursor}. 
     */ 
    private void onVendorsOrSearchQueryComplete(Cursor cursor) {
        // TODO(romannurik): stopManagingCursor on detach (throughout app) 
        mCursor = cursor;
        getActivity().startManagingCursor(mCursor);
        mAdapter.changeCursor(mCursor);
        if (mCheckedPosition >= 0 && getView() != null) {
            getListView().setItemChecked(mCheckedPosition, true);
        } 
    } 
 
    /** 
     * Handle {@link TracksQuery} {@link Cursor}. 
     */ 
    private void onTrackQueryComplete(Cursor cursor) {
        try { 
            if (!cursor.moveToFirst()) {
                return; 
            } 
 
            // Use found track to build title-bar 
            ActivityHelper activityHelper = ((BaseActivity) getActivity()).getActivityHelper();
            String trackName = cursor.getString(TracksQuery.TRACK_NAME);
            activityHelper.setActionBarTitle(trackName);
            activityHelper.setActionBarColor(cursor.getInt(TracksQuery.TRACK_COLOR));
 
            AnalyticsUtils.getInstance(getActivity()).trackPageView("/Sandbox/Track/" + trackName);
 
        } finally { 
            cursor.close();
        } 
    }