Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get field value instead of column name?
    text
    copied!<p>I want to fill a list with data from a cursor this way:</p> <pre><code> myCursor = myDBA.getAllCompanies(); startManagingCursor(myCursor); myListAdapter = new SimpleCursorAdapter(this, R.layout.company_row, myCursor, FROM, TO); myListAdapter.setViewBinder(VIEW_BINDER); companiesListView.setAdapter(myListAdapter); </code></pre> <p>I use a custom <code>ViewBinder</code> to fill two <code>TextViews</code> and one <code>ImageView</code> in each row:</p> <pre><code>private final ViewBinder VIEW_BINDER = new ViewBinder() { /** * Binds the Cursor column defined by the specified index to the * specified view. */ @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { int viewId = view.getId(); switch (viewId) { case R.id.company_name: case R.id.company_desc: Log.d(TAG, "Binding TextView"); TextView venueText = (TextView) view; venueText.setText(cursor.getString(columnIndex)); return true; case R.id.company_icon: Log.d(TAG, "Binding ImageView"); ImageView venueIcon = (ImageView) view; String iconName; iconName = cursor.getString(columnIndex); //Here I get the column name not the field value Resources resources = myContext.getResources(); Drawable drawable = resources.getDrawable(resources .getIdentifier("my.package:drawable/" + iconName, null, null)); venueIcon.setImageDrawable(drawable); return true; } return false; } }; </code></pre> <p>My problem is the <code>cursor.getString()</code> method call returns the column name not the value of the field and so I get hundreds of rows with column names. </p> <p>Update:</p> <p>My <code>getAllCompanie</code>s includes a <code>moveToFirst</code> call on the <code>Cursor</code> but still I get column names:</p> <pre><code>public Cursor getAllCompanies(){ Cursor s = myDB.query(TABLE, KEYS, WHERE, null, null, null, null); s.moveToFirst(); return s; } </code></pre>
 

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