I need to return a bit map that is inside an anonymous function and does not allow me to return it. What I need is to return it to add it to an object and then to an array list within another function. Here I show you.
This is the first onResponse feature
@Override
public void onResponse(JSONObject response) {
JSONArray json = response.optJSONArray("comercios");
JSONObject jsonObject = null;
try {
int i = 0;
for(i=0; i<json.length();i++){
Comercio comercio = new Comercio();
jsonObject = json.getJSONObject(i);
comercio.setId(jsonObject.optInt("id"));
comercio.setNombre(jsonObject.optString("nombre"));
comercio.setDireccion(jsonObject.optString("direccion"));
comercio.setDescripcion(jsonObject.optString("descripcion"));
comercio.setUrl_img(jsonObject.optString("img"));
String urlImagen = "http://192.168.0.69/webservice/img/"+comercio.getUrl_img();
Toast.makeText(getApplicationContext(),urlImagen, Toast.LENGTH_SHORT).show();
cargarWebServiceImg(urlImagen); /* ACA QUIERO QUE ME RETORNE EL BITMAP PARA PODER AGREGARLO ASI: comercio.setImg(Bitmap) */
Comercios.add(comercio);
}
adapter = new ComidasAdapter(this, Comercios);
listViewComida.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
And this is the second that I would have to return a bitmap so I can add it to the object "commerce"
private void cargarWebServiceImg(String urlImagen) {
urlImagen = urlImagen.replace(" ", "%20");
ImageRequest imageRequest = new ImageRequest(urlImagen, new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
// THIS "response" IS WHAT I WANT TO RETURN
}
}, 0, 0, ImageView.ScaleType.CENTER, null, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
request.add(imageRequest);
}
I already tried creating a final object within the function to loadWebServiceImg, add the bitmap to the object and return the object and it does not work either, it returns everything empty to me. I also try to use the function inside the previous one and it does not leave me either. I appreciate any help thanks.