Ale*_*lex 0 android android-listview picasso
我需要将此行传递到列表适配器
Picasso.with(getActivity()).load(imageurl).into(imageOrders);
Run Code Online (Sandbox Code Playgroud)
清单
ListView list= (ListView) getActivity().findViewById(R.id.list);
ListAdapter adapter=new SimpleAdapter(getActivity(),orderList,R.layout.order_usa_row,
new String[]{TAG_PRICE,TAG_TITLE,TAG_PSTATUS,TAG_PRICESYMBOL,TAG_IMAGE},new int[]{R.id.price,R.id.title,R.id.pstatus,R.id.symbol,R.id.imageOrders});
list.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
我是一个初学者,我尝试了很多,但是我不知道如何解决,请帮助
您不能将“毕加索”“传递”到适配器。您必须创建自己的自定义适配器,它听起来并不那么令人生畏。它甚至可能基于SimpleAdapter。像这样:
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){
// here you let SimpleAdapter built the view normally.
View v = super.getView(position, convertView, parent);
// Then we get reference for Picasso
ImageView img = (ImageView) v.getTag();
if(img == null){
img = (ImageView) v.findViewById(R.id.imageOrders);
v.setTag(img); // <<< THIS LINE !!!!
}
// 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;
}
}
Run Code Online (Sandbox Code Playgroud)
那么您可以只使用此类而无需在参数上添加图片(但它仍必须存在于里面orderList)。
ListView list= (ListView) getActivity().findViewById(R.id.list);
ListAdapter adapter =
new MyAdapter(
getActivity(),
orderList,
R.layout.order_usa_row,
new String[]{TAG_PRICE,TAG_TITLE,TAG_PSTATUS,TAG_PRICESYMBOL},
new int[]{R.id.price,R.id.title,R.id.pstatus,R.id.symbol});
list.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1550 次 |
| 最近记录: |