项目中要显示一个由图片和文字组成的列表,但是图片显示不出来,原因是SimpleAdapter不直接支持这种类型的数据。
API中对android.widget.SimpleAdapter.ViewBinder的解释:
This class can be used by external clients of SimpleAdapter to bind values to views.You should use this class to views that are not directly supported by SimpleAdapter or to change the way binding occurs for views supported by SimpleAdapter.
所以要对SimpleAdapter做一下处理
adapter.setViewBinder(new ViewBinder() { public boolean setViewValue(View view, Object data, String textRepresentation) { //判断是否为我们要处理的对象 if(view instanceof ImageView && data instanceof Bitmap){ ImageView iv = (ImageView) view; iv.setImageBitmap((Bitmap) data); return true; }else return false; } });