1
I created a code that perfectly brings the results via JSON from my database and fills my Listview with Strings, but I would like the database to bring the "image" column I created, the address relative to the image (Ex: http://localhost/Dashboard/Android/Image/car.jpeg) and Listview carried this image inside it through the address recorded in the database, the addresses of the images are recorded in the "image" column in my database, I have tried several ways, but I could not, I will post the code that fills my Listview only with strings, because this code is working properly:
private void showEmployee(){
Jsonobject jsonObject = null;
Arraylist> list = new Arraylist>();
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 salary = jo.getString(Config.TAG_SAL);
String image = jo.getString(Config.TAG_IMAGE);
HashMap<String, String> employees = new HashMap<>();
employees.put(Config.TAG_ID,id);
employees.put(Config.TAG_NAME,name);
employees.put(Config.TAG_SAL,salary);
employees.put(Config.TAG_IMAGE,image);
list.add(employees);
}
} catch (JSONException e) {
e.printStackTrace();
}
//ListAdapter
SimpleAdapter adapter = new SimpleAdapter(
ViewAllEmployee.this,
list,
R.layout.list_item,
new String[]{Config.TAG_ID,Config.TAG_NAME, Config.TAG_SAL, Config.TAG_IMAGE},
new int[]{R.id.id, R.id.name, R.id.salary, R.id.image}
);
listView.setAdapter(adapter);
}
You made a custom adapter for this view ?
– Lucas Queiroz Ribeiro
I tried, tried to directly put the address of the drawable images to see if the image appeared, but nothing...
– Ramom Moura
You need to make a request to fetch this image and then assign it as an Imageview resource, there are two libraries that can help you a lot with this : Picasso and Glide
– Lucas Queiroz Ribeiro