这是我的SimpleCursorAdapter
扩展类,我用它来尝试在 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);
}
}
但是,当程序到达我想从游标获取 blob 数据的代码片段时,UnsupportedOperationException
会抛出以下消息:
不支持 getBlob
我想知道我做错了什么。另外,我将MatrixCursor
自己烘焙的作为参数传递给适配器。