Transform a string array (which are links) into a Windows image on android with json

Asked

Viewed 39 times

0

I have a json on a server with image links and need to convert to imagemView, I could only open on the android screen as string showing the image link.

my json inserir a descrição da imagem aqui

my code that receives json

 StringRequest request = new StringRequest(url, new Response.Listener<String>() {
        @Override
        public void onResponse(String string) {
            parseJsonData(string);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            Toast.makeText(getApplicationContext(), "Some error occurred!!", Toast.LENGTH_SHORT).show();
            dialog.dismiss();
        }
    });

    RequestQueue rQueue = Volley.newRequestQueue(MainActivity.this);
    rQueue.add(request);
}

void parseJsonData(String jsonString) {
    try {
        JSONObject object = new JSONObject(jsonString);
        JSONArray fruitsArray = object.getJSONArray("fruits");
        ArrayList al = new ArrayList();

        for(int i = 0; i < fruitsArray.length(); ++i) {
            al.add(fruitsArray.getString(i));
        }

        ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, al);
        fruitsList.setAdapter(adapter);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    dialog.dismiss();
}
  • on the server side, convert the images to Base64 string. When receive on android moves from Base64 to image again

  • @How to convert Array? I had not yet thought about Base64 I will try, but I do not know how to pick up the Array that will come and play for picture.

  • you will need to make your own Adapter, look at this tutorial http://blog.alura.com.br/personalizando-uma-listview-no-android/, the part that is passed the java drawable, you make a function that takes the json Base64 and turns into image

  • @Andersoncanteiro in this case I will receive in string is not? if that is I am already receiving in string the url of the images, and I transformed an image using Base64 became a very big code, has an example?

  • I’m getting the link of each image on android in string array, I’m just not knowing how to pick up the array string and run

  • Base64 gets big, but then on android you only have to convert, in case you send the url, vc will have to make another request to the internet. That may be the case, too, but the way I put it, you’d only request

  • @Andersoncanteiro you have an example? because I am beginner, about json and this subject I am new, I would be grateful, thank you

  • No need to convert to Base64. Libraries like Glide and Picasso can load the images from the urls directly into a ImageView.

  • Marlos, I’m gonna see if I can put something together, you really don’t have to convert, I told you to convert just to make a request. But if that’s okay, you can use Leonardo’s suggestion.

Show 4 more comments

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.