展会信息港展会大全

SimpleAdapter无法自动适配BitMap android开发学习
来源:互联网   发布日期:2015-10-02 16:13:28   浏览:1014次  

导读:SimpleAdapter无法自动适配BitMap 需求需要将一组图片和文字介绍通过GridView排列,我选择了SimpleAdapter来适配文字和图片的信息。因为我需要去取网络的图片直接转换 为Bitmap格式(写了个工具类转换),以为写完......

SimpleAdapter无法自动适配BitMap

需求需要将一组图片和文字介绍通过GridView排列,我选择了SimpleAdapter来适配文字和图片的信息。因为我需要去取网络的图片直接转换 为Bitmap格式(写了个工具类转换),以为写完后可以完成适配。当运行的时候发现并没有显示图片。后来查阅了相关的资料。

android.widget.SimpleAdapter.ViewBinder 默认规则并不能直接绑定BitMap

后来查阅相关网站 Luki老兄说的话确实给了不错的提示。

API也指出

This class can be used by external clients of SimpleAdapter to bind values to views. You should use this class to bind values to views that are not directly supported by SimpleAdapter or to change the way binding occurs for views supported by SimpleAdapter.

重写改写这个类的

ViewBinder

public class MyViewBinder implements ViewBinder {

@Override

public boolean setViewValue(View view, Object data,

String textRepresentation) {

if( (view instanceof ImageView) &&(data instanceof Bitmap) ) {

ImageView iv = (ImageView) view;

Bitmap bm = (Bitmap) data;

iv.setImageBitmap(bm);

return true;

}

return false;

}

}

然后

赞助本站

人工智能实验室

相关热词: SimpleAdapter BitMap

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港