SimpleAdapter加载网络图片
编辑于 2022-06-05 17:10:15 阅读 1188
要实现加载网络图片,需要使用SimpleAdapter中的setViewBinder()
方法
SimpleAdapter simpleAdapter = new SimpleAdapter(this.getActivity(),
menuList, //数据源
R.layout.grid_item, //xml实现
new String[]{"avatar", "name", "memo"}, //对应map的Key
new int[]{R.id.avatar,R.id.name,R.id.memo}); //对应R的Id
simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if (view instanceof ImageView) {
ImageView iv = (ImageView) view;
Glide.with(iv.getContext()).load("https://xxx.net/"+data).into(iv);
return true;
}
return false;
}
});