我无法通过毕加索"到适配器。我必须创建自己的自定义适配器。它甚至可能基于SimpleAdapter。像这样:
aldigim_profil_URL是图片网址
public class MyAdapter extends SimpleAdapter {
public MyAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
ImageView img = (ImageView) v.getTag();
if (img == null) {
img = (ImageView) v.findViewById(R.id.alinan_list_profil_url);
v.setTag(img);
}
String url_test ="http://" + aldigim_profil_URL.toString();
// get the url from the data you passed to the `Map`
String url = ((Map)getItem(position)).get(url_test);
// do Picasso
Picasso.with(v.getContext()).load(url).into(img);
// return the view
return v;
}
}
我的listadapter是这样的;
contactList是来自Json Websercive的返回图片网址列表
ListAdapter adapter = new MyAdapter(getActivity(), contactList,
R.layout.activity_list_alinan_gorevler, new String[]{"Gorevi_Veren", "Gorev_Adi", "Tarih"},
new int[]{R.id.alinan_list_gorev_veren, R.id.alinan_list_gorev_adi, R.id.alinan_list_tarih});
listView.setAdapter(adapter);
我的错误是
String url =((Map)getItem(position))。get(url_test);
错误:(287,54)错误:不兼容的类型:对象无法转换为String
答案 0 :(得分:1)
试试这个
public class MyAdapter extends SimpleAdapter {
public MyAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
ImageView img = (ImageView) v.getTag();
if (img == null) {
img = (ImageView) v.findViewById(R.id.alinan_list_profil_url);
v.setTag(img);
}
String url_test ="http://" + aldigim_profil_URL.toString();
// get the url from the data you passed to the `Map`
String url = ((Map)getItem(position)).get(TAG_IMAGE);
// do Picasso
Picasso.with(v.getContext()).load(url).into(img);
// return the view
return v;
}
}