【发布时间】:2019-09-15 12:58:51
【问题描述】:
我有一个简单的列表适配器,我想在其中显示带有一些文本信息的食物图像。到目前为止,我知道我可以使用 AQuery 或 Picasso 之类的库来完成它,但是在阅读了很多教程后我无法弄清楚如何实现它。
我在我的依赖项中添加了毕加索库。假设我的图像视图 ID 是 ImgViewFood
活动
JSONArray jsonArr = jsonObj.getJSONArray("foodnames");
for (int i = 0; i < jsonArr.length(); i++) {
HashMap<String, String> food = new HashMap<>();
JSONObject jsonObj = jsonArr.getJSONObject(i);
String name = jsonObj.getString("food_name");
String url = jsonObj.getString("img_url");
food.put("foodname", name);
foodList.add(food);
}
ListAdapter adapter = new SimpleAdapter(
FoodListActivity.this, foodList,
R.layout.list_food_detail, new String[]{"foodname"}, new int[]{R.id.view_food_name});
listviewFood.setAdapter(adapter);
【问题讨论】:
-
查看毕加索官方网站。 square.github.io/picasso
-
我可以使用 picasso 显示图像,这不是问题,问题是如何使用 listadapter 实现它。
-
需要完整的代码来看看。你的 ListAdapter 类在哪里?
-
Atlast 想通了。解决了。我正在发布我的解决方案。
标签: android android-listview picasso listadapter simpleadapter