0

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);
}
Daniel Waghorn
  • 2,997
  • 2
  • 20
  • 33
guccini
  • 1
  • 2
  • Possible duplicate of [Get images from PHP-MySql server to Android using json](http://stackoverflow.com/questions/29342749/get-images-from-php-mysql-server-to-android-using-json) – Ramesh-X Dec 29 '15 at 16:02
  • this is a sample with base64, i sesarch how can use in arrylist – guccini Dec 29 '15 at 16:39
  • have anyone an example based on my code? so can i better understand how it work – guccini Dec 30 '15 at 10:28

0 Answers0