如何将我的数据库中的图像加载到android应用程序中并将其放入列表视图中。数据库是MySQL和图像以PNG格式存储如何在android中加载图像
这是我的代码检索我的数据库中的数据。该a_emblem是ImageView的,在我的JSON镜像文件
private void showResult() {
JSONObject jsonObject;
ArrayList<HashMap<String, String>> list = new ArrayList<>();
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY1);
for (int i = 0; i < result.length(); i++) {
JSONObject jo = result.getJSONObject(i);
String a_shortcut = jo.getString(Config.TAG_a_shortcut);
String a_emblem = jo.getString(Config.TAG_a_emblem);
String gold = jo.getString(Config.TAG_gold);
String silver = jo.getString(Config.TAG_silver);
String bronze = jo.getString(Config.TAG_bronze);
String total = jo.getString(Config.TAG_total);
HashMap<String, String> match = new HashMap<>();
match.put(Config.TAG_a_shortcut, a_shortcut);
match.put(Config.TAG_a_emblem, a_emblem);
match.put(Config.TAG_gold, gold);
match.put(Config.TAG_silver, silver);
match.put(Config.TAG_bronze, bronze);
match.put(Config.TAG_total, total);
list.add(match);
}
} catch (JSONException e) {
e.printStackTrace();
}
ListAdapter adapter = new SimpleAdapter(
getActivity(), list, R.layout.standlayout,
new String[]{Config.TAG_a_shortcut, Config.TAG_a_emblem, Config.TAG_gold, Config.TAG_silver, Config.TAG_bronze, Config.TAG_total},
new int[]{R.id.shortcut, R.id.img, R.id.gold, R.id.silver, R.id.bronze, R.id.total});
lv.setAdapter(adapter);
}
我不认为这可以回答没有更多的上下文。这些图像如何存储在数据库中?什么是数据库呢? –
你应该使用一个自定义的Adapter类来做到这一点。 – sam
@ KenY-N添加了数据库和图片如何存储 – orange