How can I get an image from MySQL? I'm using an ArrayList, on the MySQL server the image path is stored as varchar
.
private void showEmployee(){
JSONObject jsonObject = null;
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
for(int i = 0; i<result.length(); i++){
JSONObject jo = result.getJSONObject(i);
String id = jo.getString(Config.TAG_ID);
String name = jo.getString(Config.TAG_NAME);
String designation = jo.getString(Config.TAG_DESG);
String salary = jo.getString(Config.TAG_SAL);
String image = jo.getString(Config.TAG_IMG);
HashMap<String,String> employees = new HashMap<>();
employees.put(Config.TAG_ID,id);
employees.put(Config.TAG_NAME,name);
employees.put(Config.TAG_DESG,designation);
employees.put(Config.TAG_SAL,salary);
employees.put(Config.TAG_IMG,String.valueOf(image));
list.add(employees);
}
} catch (JSONException e) {
e.printStackTrace();
}
ListAdapter adapter = new SimpleAdapter(
MainActivity1.this, list, R.layout.list_item,
new String[]{Config.TAG_ID,Config.TAG_NAME,Config.TAG_DESG,Config.TAG_SAL, Config.TAG_IMG},
new int[]{R.id.id, R.id.name, R.id.desg, R.id.sal, R.id.imageView_1});
listView.setAdapter(adapter);
}