Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's how I did one of my adapters. First, here's the code that does the query:</p> <pre><code>private void query (long uuid) { // Fill list using adapter String cols[] = { Instances.TITLE }; // dummy field; we will set all fields together in ViewBinder int fields[] = { R.id.node_text }; cursorAdapter = new CursorAdapter (this, R.layout.row_view, null, // no cursor yet cols, fields, Adapter.NO_SELECTION); cursorAdapter.setViewBinder (new MyViewBinder(this)); // Setup the adapter filter - this does the query work. cursorAdapter.setFilterQueryProvider (new FilterQueryProvider() { @Override public Cursor runQuery (CharSequence constraint) { Cursor cursor = getContentResolver().query (...your params...); return cursor; } }); listView.setAdapter (cursorAdapter); listView.setTextFilterEnabled (true); // Force initial query - notice we setup an adapter with a null cursor. cursorAdapter.getFilter().filter (null); } </code></pre> <p>Notice I did not subclass the adapter. Instead, I subclassed ViewBinder. Normally one lets each call to ViewBinder set one view at a time. I thought it would be more efficient to do all the views together. Here's how I did it:</p> <pre><code>private class MyViewBinder implements ViewBinder { @Override public boolean setViewValue (View view, Cursor cursor, int column) { // Do all columns in one pass. if (column != SelectAndroidEvent.instancesTitleCol) throw new IllegalStateException ("viewbinder should only be called for title; " + "col: " + column); // Find encompassing layout. ViewGroup parentView = (ViewGroup)view.getParent(); // Get fields from parentView. TextView titleView = (TextView)view; TextView field2 = (TextView)parentView.findViewById (R.id.field2); ... // set all fields together - easier. view.setText (cursor.getString (column); field2.setText (cursor.getString (FIELD2_COL); ... return true; } } </code></pre> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload