Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-如何在SimpleApter列表视图中显示图片_Java_Android_Android Listview_Picasso_Simpleadapter - Fatal编程技术网

Java Android-如何在SimpleApter列表视图中显示图片

Java Android-如何在SimpleApter列表视图中显示图片,java,android,android-listview,picasso,simpleadapter,Java,Android,Android Listview,Picasso,Simpleadapter,我正在尝试在SimpleAdapter列表视图中显示te图片。我的项目中包括了毕加索,但我不知道如何将毕加索与SimpleAdapter结合使用 List<HashMap<String, String>> featured = new ArrayList<HashMap<String, String>>(); for (int i=0;i<ids.length;i++){ HashMa

我正在尝试在SimpleAdapter列表视图中显示te图片。我的项目中包括了毕加索,但我不知道如何将毕加索与SimpleAdapter结合使用

List<HashMap<String, String>> featured = new ArrayList<HashMap<String, String>>();

            for (int i=0;i<ids.length;i++){
                HashMap<String, String> hm = new HashMap<String, String>();
                hm.put("productname", names[i]);
                hm.put("productprice", prices[i]);
                hm.put("productimage", images[i]);
                featured.add(hm);
            }

            String[] from = {"productname", "productprice", "productimage"};
            int[] to = {R.id.tv_ProductName, R.id.tv_ProductPrice, R.id.icon};

            SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, featured, R.layout.listitem_featured, from, to);
            HorizontalListView featuredList = (HorizontalListView) findViewById(R.id.lv_Featured);
            featuredList.setAdapter(adapter);
List-featured=new-ArrayList();
对于(int i=0;i您不能将毕加索“传递”给适配器。您必须创建自己的自定义适配器,这并不像听起来那么令人畏惧。它甚至可能基于
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
  // maybe you could do that by using many ways to start

    Picasso.with(context).load(url)
            .resize(imageWidth, imageWidth).into(img);

  // return the view
  return v;
   }
}
然后您可以只使用这个类,而不使用参数上的图像(但它必须仍然存在于orderList中)


对于图像大小,我认为您需要重新调整它的大小!!如上面的例子
。调整大小(imageWidth,imageWidth)
希望这有帮助!!

我如何定义和使用TAG\u名称、TAG\u价格和TAG\u图像?可能是个愚蠢的问题…不…当然没有愚蠢的问题,但未问的问题是一个!!总之,这只是个例子,TAG\u名称、TAG\u价格和TAG\u图像指图像位置为ex等。你可以根据你的代码需要使用它们!好的,我明白了!bu我有一个url数组,由异步任务从php服务器检索。字符串声明如下:
private static final string TAG\u SUCCESS=“SUCCESS”
我如何声明数组?你需要根据你的要求更改MyAdapter参数,包括产品名称、价格和图像路径的数组!正如我告诉你的,例如你如何使用毕加索……对不起,我真的不明白。你能给我一个例子看看我的代码吗。我不知道如何获得URL数组
图像[]
并在MyAdapter类中使用它们?我知道需要在这里检索url
String url=((Map)getItem(position))。get(…);
Picasso.with(context).load(yoururl)
            .resize(imageWidth, imageWidth).into(holder.imageItem);
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);