【发布时间】:2013-05-23 07:10:01
【问题描述】:
这是我的 SimpleCursorAdapter 扩展类,我使用它来尝试在 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 数据的代码 sn-p 时,会抛出 UnsupportedOperationException 并显示消息:
不支持getBlob
我想知道我做错了什么。另外,我将自己烘焙的MatrixCursor 作为参数传递给适配器。
【问题讨论】:
-
哪个android版本抛出异常?
-
安卓4.2.2版本
-
您的设备装有 Android 4.2.2 或者您正在针对 Android 4.2.2 进行编译?
标签: android listview simplecursoradapter android-cursoradapter android-cursor