【问题标题】:Pass picasso into listview将毕加索传递到列表视图
【发布时间】:2017-12-13 11:55:37
【问题描述】:

我无法将毕加索“传递”到适配器。我必须创建自己的自定义适配器。它甚至可能基于 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 返回的图片 url 列表

        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) 错误:不兼容的类型:对象无法转换为字符串

【问题讨论】:

  • 请检查我的回答。
  • 添加您的 Map 类代码以便更好地理解。这个错误似乎 getItem(Pos).get(url) 没有返回字符串类型。检查 Map 类中的 Map.get(url) 返回字符串类型。

标签: android picasso listadapter


【解决方案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;
    }
 }

【讨论】:

    猜你喜欢
    • 2014-09-06
    • 2018-12-08
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多