Here is my SimpleCursorAdapter
extension class which I use trying to display information about contacts in a ListView
:
private class CustomContactsAdapter extends SimpleCursorAdapter {
private int layout;
private LayoutInflater inflater;
public CustomContactsAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to, 0);
this.layout = layout;
inflater = LayoutInflater.from(context);
}
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = inflater.inflate(layout, parent, false);
return v;
}
@Override
public void bindView(View v, Context context, Cursor cur) {
MatrixCursor c = (MatrixCursor) cur;
final String name = c.getString(c.getColumnIndex(COLUMN_NAME));
final String org = c.getString(c.getColumnIndex(COLUMN_ORG));
final byte[] image = c.getBlob(c.getColumnIndex(COLUMN_PHOTO));
ImageView iv = (ImageView) v.findViewById(R.id.contact_photo);
if(image != null && image.length > 3) {
iv.setImageBitmap(BitmapFactory.decodeByteArray(image, 0, image.length));
}
TextView tname = (TextView) v.findViewById(android.R.id.text1);
tname.setText(name);
TextView torg = (TextView) v.findViewById(android.R.id.text2);
torg.setText(org);
}
}
But when the program reaches the code snippet where I want to get blob data from cursor an UnsupportedOperationException
is thrown there with message:
getBlob is not supported
I want to know what am I doing wrong. Also, I pass a MatrixCursor
baked by myself as a parameter to the adapter.