Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A <code>ViewBinder</code> will get called for every view declared in the <code>to</code>(adapter's constructor) array passed when creating the adapter. Right now you're not passing the <code>ImageView</code>(through it's id) so the <code>ViewBinder</code> will not get called for the <code>ImageView</code>, it will only get called for the views with the ids <code>R.id.list_item_name</code>, <code>R.id.list_item_phone</code> and <code>R.id.list_item_companyname</code>. This is why you get that <code>ClassCastException</code>, because you wrongly assume that the view passed to the <code>ViewBinder</code> is the <code>ImageView</code>(this is another mistake you made, because you don't look at the ids of the views passed to the <code>ViewBinder</code> to see which view is set to be binded at that moment with data from the <code>Cursor</code>).</p> <p>To solve it you need to let the adapter know that you also want the <code>ImageView</code> from the row to get binded(notice the extra column and id):</p> <pre><code>SimpleCursorAdapter myAdapter = new SimpleCursorAdapter( getApplicationContext(), R.layout.listview_each_item, cursor, new String[] { SQLiteAdapter.KEY_NAME,SQLiteAdapter.KEY_PHONE, SQLiteAdapter.KEY_COMPANYNAME, SQLiteAdapter.KEY_IMAGE}, new int[] { R.id.list_item_name,R.id.list_item_phone, R.id.list_item_companyname, R.id.list_item_image},0); </code></pre> <p>Then change the <code>ViewBinder</code> to handle setting the image, letting the adapter bind the other views on its own:</p> <pre><code>@Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.list_item_image) { // we have our ImageView so bind the image byte[] byteArray = cursor.getBlob(columnIndex); ((ImageView)view).setImageBitmap(BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length)); return true; // return true to let the adapter know that we handled this view on our own } return false; // return false for any other view so the adapter will bind the data on its own } </code></pre> <p>This:</p> <pre><code>mvb.setViewValue(image, cursor, cursor.getColumnIndex(SQLiteAdapter.KEY_IMAGE)); </code></pre> <p>is incorrect. You don't call <code>setViewValue()</code> on your own, the adapter will call it in the <code>getView()</code> method for each of the views with the ids from the <code>to</code> array to set the data on them.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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