// 处理simpleAdapter中包括bitmap类型 
        adapter.setViewBinder(new ViewBinder() { 
            public boolean setViewValue(View view, Object data, 
                    String textRepresentation) { 
                if (view instanceof ImageView && data instanceof Bitmap) { 
                    ImageView image = (ImageView) view; 
                    image.setImageBitmap((Bitmap) data); 
                    return true; 
                } 
                return false; 
            } 
        });

完整示例如下:

listData = this.GetPersonalData(); 
        adapter = new SimpleAdapter(this, listData, 
                R.layout.personal_list_item, new String[] { "label", "image", 
                        "arrows", "value" }, new int[] { R.id.personal_label, 
                        R.id.personal_img, R.id.list_arrows, 
                        R.id.personal_value }); 
 
        // 处理simpleAdapter中包括bitmap类型 
        adapter.setViewBinder(new ViewBinder() { 
            public boolean setViewValue(View view, Object data, 
                    String textRepresentation) { 
                if (view instanceof ImageView && data instanceof Bitmap) { 
                    ImageView image = (ImageView) view; 
                    image.setImageBitmap((Bitmap) data); 
                    return true; 
                } 
                return false; 
            } 
        }); 
 
        mainListView.setAdapter(adapter);
private List<Map<String, Object>> GetPersonalData() { 
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); 
 
        Map<String, Object> map = new HashMap<String, Object>(); 
 
        map.put("label", 
                this.getResources().getString(R.string.personal_headphoto)); 
        map.put("image", 
                preferences.getString("photo", null) == null ? R.drawable.head 
                        : this.StringToBitMap(preferences.getString("photo", 
                                null)));//经过上述view.setViewBing之后在put值的时候就可以直接加入BitMap类型图片进行显示了 
        map.put("arrows", R.drawable.arrows_right); 
        list.add(map); 
 
        map = new HashMap<String, Object>(); 
        map.put("label", this.getResources().getString(R.string.personal_name)); 
        map.put("value", "APP测试"); 
        list.add(map); 
 
        map = new HashMap<String, Object>(); 
        map.put("label", 
                this.getResources().getString(R.string.personal_username)); 
        map.put("value", "xxx"); 
        list.add(map); 
 
        map = new HashMap<String, Object>(); 
        map.put("label", 
                this.getResources().getString(R.string.personal_disease)); 
        map.put("value", preferences.getString("disease", "无")); 
        map.put("arrows", R.drawable.arrows_right); 
        list.add(map); 
        return list; 
    }

注:着色部分意思为图片资源我用的base64所以这里边我转化了一下。

发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

resumable.js —— 基于 HTML 5 File API 的文件上传组件 支持续传后台c#实现详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。