使用mysql URL,atraylist hashmap中的毕加索加载图像



问题:

我想使用毕加索将图像URL转换为图像。

解释:

使用JSON查询,从数据库中接收数据。数据包含我要转换为图像的URL(最好使用毕加索)。

现在的作用:

所有数据都放在阵列列表中。检索数据时,所有数据显示了图像(使用XML中的ImageView)。

我尝试了

将所有毕加索选项放在各处,但是我不知道如何在arraylist或hashmap中使用毕加索。

代码

这里我想实现的代码部分。如果需要更多,我将添加更多。

ongreate

之前的代码
ArrayList<HashMap<String, String>> recipesList;

加载列表的代码

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_two);
    // Hashmap for ListView
    recipesList = new ArrayList<HashMap<String, String>>();
    // Loading ingredients in Background Thread
    new LoadAllRecipes().execute();
    // Get listview
    ListView lv = getListView();

检索信息的代码,包括毕加索标签

if (success == 1) {
    // recipies found
    // Getting Array of Ingredients
    recipes = json.getJSONArray(TAG_recipes);
    // looping through all recipes
    for (int i = 0; i < recipes.length(); i++) {
    JSONObject c = recipes.getJSONObject(i);
    // Storing each json item in variable
    String id = c.getString(TAG_PID);
    String name = c.getString(TAG_NAME);
    String photo = c.getString(TAG_PHOTO);
    String price = c.getString(TAG_PRICE);
    String time = c.getString(TAG_TIME);
    // creating new HashMap
    HashMap<String, String> map = new HashMap<String, String>();
    // adding each child node to HashMap key => value
    map.put(TAG_PID, id);
    map.put(TAG_NAME, name);
    map.put(TAG_PRICE, price);
    map.put(TAG_TIME, time);
    Picasso.get().load(map.put( TAG_PHOTO, photo ));
    // adding HashList to ArrayList
    recipesList.add(map);
    }

底部的适配器

  /**
  * Updating parsed JSON data into ListView
  * */
 ListAdapter adapter;
 adapter = new SimpleAdapter(
      ActivityTwo.this, recipesList,
      R.layout.activity_two_details_cards, new String[] { TAG_PID,
      TAG_NAME, TAG_PRICE, TAG_TIME, TAG_PHOTO},
      new int [] { R.id.pid, R.id.name, R.id.price, R.id.time, R.id.imagePhoto});// updating listview
      setListAdapter(adapter);
      }

因为map.put return

与键关联的先前值,如果没有 映射密钥。(零返回还可以指示地图 如果实施支持 零值。)

https://docs.oracle.com/javase/7/docs/api/java/java/util/map.html#put(k,%20V)

在您的示例中,特定键的先前地图值为null。您可以将代码修复为

...
map.put(TAG_PHOTO, photo);
Picasso.get().load(map.get(TAG_PHOTO));
...

最新更新