3

我正在尝试将位图从 url 传递到我的列表我将位图作为对象传递但我的图像不会显示

for(int i=0;i<CarsArray.length();i++){
    HashMap<String, Object> map = new HashMap<String, Object>();


    JSONObject e = CarsArray.getJSONObject(i);

    map.put("InventoryID",  String.valueOf(i));
    map.put("Year", " " +  e.getString("Year") + " " + e.getString("Make") + " " + e.getString("Model"));
    map.put("Stock Number", "Stock#: " + e.getString("StockNumber"));
    map.put("VIN", "VIN: " + e.getString("VIN"));
    map.put("Color", "Exterior Color: " + e.getString("ExteriorColor"));
    map.put("InColor", "Interior Color: " + e.getString("InteriorColor"));
    map.put("Mileage", "Odometer: " + e.getString("Mileage"));
    map.put("Price", "$" + e.getString("Price") + "0");
    map.put("VehicleStatus", e.getString("VehicleStatus"));
    map.put("InsertedDate", e.getString("InsertedDate"));
    bimage =  getBitmapFromURL(imageUrl);
    map.put("Image", bimage);
    mylist.add(map);

}
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.parsejson,
        new String[] { "Year", "Stock Number", "VIN", "Color", "Mileage", "Price", "VehicleStatus", "InColor", "InsertedDate", "Image"},
        new int[] { R.id.item_title, R.id.item_subtitle, R.id.item_subtitle2, R.id.item_subtitle3 , R.id.item_subtitle4,
                R.id.item_subtitle5, R.id.item_subtitle6, R.id.item_subtitle8,  R.id.item_subtitle9, R.id.imageView1});

setListAdapter(adapter);
4

2 回答 2

1

使用自定义适配器并覆盖 getView() 方法。在该方法内部使用这些代码行来显示图像:

ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setImageBitmap(mylist.get("Image")); 
于 2013-02-16T19:51:27.400 回答
0

替换您的以下代码行

bimage =  getBitmapFromURL(imageUrl);
map.put("Image", bimage);

bimage =  getBitmapFromURL(imageUrl);
Drawable d = new BitmapDrawable(getResources(),bitmap);
 map.put("Image", d);
于 2013-02-16T09:35:15.147 回答