【发布时间】:2019-08-01 19:25:05
【问题描述】:
问题:
我想将我的图片 URL 转换为使用 Picasso 的图片。
解释:
使用 JSON 查询,从数据库接收数据。数据包含一个我想转换为图像的 URL(最好使用毕加索)。
现在做了什么:
所有数据都放在一个 ArrayList 中。检索数据时,除图像外的所有数据都显示(使用 XML 中的 ImageView)。
我尝试了什么
把毕加索的所有选项都放在各处,但我不知道如何在 ArrayList 或 HashMap 中使用毕加索。
代码
这里是我想要实现的代码。如果需要更多,我会添加更多。
OnCreate 之前的一段代码
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);
}
【问题讨论】:
标签: java arraylist hashmap picasso