2017-12-13 13 views
0

「ピカソを渡す」ことができません。私は自分のカスタムアダプターを作成する必要があります。それはSimpleAdapterに基づいているかもしれません。このように:ピカソをリストビューに渡す

aldigim_profil_URLは、画像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); 

からの戻り画像のURLのリストであり、私の誤差がある

文字列のURL =((マップ)のgetItem(位置))を取得(url_test)。

Error:(287, 54) error: incompatible types: Object cannot be converted to String

+0

を試してみてください私の答えを確認してください。 –

+0

マップクラスコードを追加して、より理解してください。このエラーはgetItem(Pos).get(url)が文字列型を返さないようです。 Check Map.get(url)Mapクラスの文字列型を返します。 –

答えて

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; 
    } 
} 
関連する問題