Android CursorAdapter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android CursorAdapter class.

This code example shows how to use the following methods:changeCursor, getCount
        if (mCursorAdapter == null) {
            mCursorAdapter = newAdapter();
 
            setListAdapter(mCursorAdapter);
        } else { 
            mCursorAdapter.changeCursor(mCursor);
        } 
 
        if (mInitialSelection >=0 && mInitialSelection < mCursorAdapter.getCount()) {
            setSelection(mInitialSelection);
            getListView().setFocusableInTouchMode(true);
            boolean gotfocus = getListView().requestFocus();
        } 
    } 
 
    protected CursorAdapter newAdapter() {
        return new SimpleCursorAdapter(this,
                    android.R.layout.simple_list_item_2,
                    mCursor, COLUMN_NAMES, VIEW_NAMES);
    } 
6
CodeRank
This code example shows how to use the following methods:changeCursor
    } 
  } 
 
  @Implementation 
  public void changeCursor(Cursor c) {
    realSimpleCursorAdapter.changeCursor(c);
    // rescan columns in case cursor layout is different 
    findColumns(mOriginalFrom);
  } 
 
  /** 
   * Change the cursor and change the column-to-view mappings at the same time. 
   * 
   * @param c The database cursor.  Can be null if the cursor is not available yet. 
   * @param from A list of column names representing the data to bind to the UI.  Can be null 
   *            if the cursor is not available yet. 
   * @param to The views that should display column in the "from" parameter. 
   *            These should all be TextViews. The first N views in this list 
   *            are given the values of the first N columns in the from 
   *            parameter.  Can be null if the cursor is not available yet. 
6
CodeRank
This code example shows how to use the following methods:changeCursor, getCount
        if (mCursorAdapter == null) {
            mCursorAdapter = newAdapter();
 
            setListAdapter(mCursorAdapter);
        } else { 
            mCursorAdapter.changeCursor(mCursor);
        } 
 
        if (mInitialSelection >=0 && mInitialSelection < mCursorAdapter.getCount()) {
            setSelection(mInitialSelection);
            getListView().setFocusableInTouchMode(true);
            boolean gotfocus = getListView().requestFocus();
        } 
    } 
 
    protected CursorAdapter newAdapter() {
        return new SimpleCursorAdapter(this,
                    android.R.layout.simple_list_item_2,
                    mCursor, COLUMN_NAMES, VIEW_NAMES);
    } 
6
CodeRank
This code example shows how to use the following methods:changeCursor
        } 
    } 
 
    @Implementation 
    public void changeCursor(Cursor c) {
        realSimpleCursorAdapter.changeCursor(c);
        // rescan columns in case cursor layout is different 
        findColumns(mOriginalFrom);
    } 
 
    /** 
     * Change the cursor and change the column-to-view mappings at the same time. 
     * 
     * @param c The database cursor.  Can be null if the cursor is not available yet. 
     * @param from A list of column names representing the data to bind to the UI.  Can be null 
     *            if the cursor is not available yet. 
     * @param to The views that should display column in the "from" parameter. 
     *            These should all be TextViews. The first N views in this list 
     *            are given the values of the first N columns in the from 
     *            parameter.  Can be null if the cursor is not available yet. 
6
CodeRank
This code example shows how to use the following methods:getCursor
	@Override 
	protected void onPause() { 
		CursorAdapter adapter = (CursorAdapter) getListAdapter();
		if (adapter != null) {
			// Properly close the adapter cursor 
			Cursor cursor = adapter.getCursor();
			stopManagingCursor(cursor);
			cursor.close();
			setListAdapter(null);
		} 
 
		super.onPause(); 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getFilter, runQueryOnBackgroundThread
        mcontactFilter.addTextChangedListener(new TextWatcher() {
			public void onTextChanged(CharSequence s, int start, int b, int c) {}
			public void beforeTextChanged(CharSequence s, int st, int c, int a) {}
			 
			public void afterTextChanged(Editable s) {
				adapter.runQueryOnBackgroundThread(s);
				adapter.getFilter().filter(s.toString());
			} 
		}); 
 
 
        // Populate the contact list 
        String[] from = new String[] {col_display_name};
        int[] to = new int[] {android.R.id.text1};
        int layout = android.R.layout.simple_list_item_1;
        adapter = new SimpleCursorAdapter(this, layout, runQuery(null), from, to);
        adapter.setFilterQueryProvider(this);
        mContactList.setAdapter(adapter);
         
        mContactList.setOnItemClickListener(new OnItemClickListener() {
5
CodeRank
This code example shows how to use the following methods:getItem
 
    private Long getSelectedFeedId(int selectedPosition) {
        Object o = null;
        Long feedId = null;
        try { 
            o = sca.getItem(selectedPosition);
            if (o != null) {
 
                Cursor c = (Cursor) o;
                feedId = c.getLong(c.getColumnCount() - 1);
            } 
        } catch (RuntimeException rte) {
            // ignored 
        } 
        return feedId;
    } 
 
    @Override 
    public String getDefaultStatusBarTitle() {
        StringBuilder sb = new StringBuilder();
5
CodeRank
This code example shows how to use the following methods:getCount
                mGeneration++;
                ThreadedCursorAdapter.this.notifyDataSetInvalidated();
            } 
 
        }; 
        mSize = mCursorAdapter.getCount();
        HandlerThread thread = new HandlerThread("threaded_adapter_" + this,
                Process.THREAD_PRIORITY_BACKGROUND);
        thread.start();
        mLoadHandler = new Handler(thread.getLooper()) {
            @SuppressWarnings("unchecked") 
            @Override 
            public void handleMessage(Message msg) {
                if (DEBUG) {
                    Log.d(LOGTAG, "loading: " + msg.what);
                } 
                loadRowObject(msg.what, (LoadContainer) msg.obj);
            } 
        }; 
        mHandler = new Handler() {
5
CodeRank
This code example shows how to use the following methods:changeCursor
        } 
    } 
 
    @Implementation 
    public void changeCursor(Cursor c) {
        realSimpleCursorAdapter.changeCursor(c);
        // rescan columns in case cursor layout is different 
        findColumns(mOriginalFrom);
    } 
 
    /** 
     * Change the cursor and change the column-to-view mappings at the same time. 
     * 
     * @param c The database cursor.  Can be null if the cursor is not available yet. 
     * @param from A list of column names representing the data to bind to the UI.  Can be null 
     *            if the cursor is not available yet. 
     * @param to The views that should display column in the "from" parameter. 
     *            These should all be TextViews. The first N views in this list 
     *            are given the values of the first N columns in the from 
     *            parameter.  Can be null if the cursor is not available yet. 
5
CodeRank
This code example shows how to use the following methods:notifyDataSetChanged, getItem
    } 
 
    /** {@inheritDoc} */ 
    @Override 
    public void onListItemClick(ListView l, View v, int position, long id) {
        final Cursor cursor = (Cursor) mAdapter.getItem(position);
        String vendorId = cursor.getString(VendorsQuery.VENDOR_ID);
        if (mCallbacks.onVendorSelected(vendorId)) {
            mSelectedVendorId = vendorId;
            mAdapter.notifyDataSetChanged();
        } 
    } 
 
    @Override 
    public Loader<Cursor> onCreateLoader(int id, Bundle data) {
        return new CursorLoader(getActivity(), mVendorsUri, VendorsQuery.PROJECTION, null, null,
                ScheduleContract.Vendors.DEFAULT_SORT); 
    } 
 
    @Override 
5
CodeRank

Related Android CursorAdapter Questions & Answers:

See Code Examples for Android CursorAdapter Methods: