0

这是我的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自己烘焙的作为参数传递给适配器。

4

1 回答 1

1

这就是Android 1.6 和 Android 2.3getBlob(int)中from的实现。MatrixCurosr

public byte[] getBlob(int column) {
    throw new UnsupportedOperationException("getBlob is not supported");
}

这就是getBlob(int)Android ICS的实现

 @Override
 public byte[] getBlob(int column) {
        Object value = get(column);
        return (byte[]) value;
 }

可能您想以MatrixCursorICS 方式子类化和实现 getBlob

于 2013-05-23T07:31:01.800 回答