Parsing data from Json as a collection of image to Picasso

前端 未结 2 676
攒了一身酷
攒了一身酷 2021-01-29 09:51

I tried to parse a collection of image to recyclerview as gridview using Picasso library but i cannot make it work

Note : i dont h

相关标签:
2条回答
  • 2021-01-29 10:07

    You can't load multiple images in single ImageView so try to load each image in different ImageView, As I have observerd there are fixed 3 number of images in each module so add 3 ImageViews in your xml layout and apply images separately.

    0 讨论(0)
  • 2021-01-29 10:17

    You would need a List<String> imageUrls to save urls to be viewed by picasso, no need for special object for that. To solve it, change your json parsing code to

    try {
        JSONArray entries = response.getJSONObject("feed").getJSONArray("entry");
        int count = entries.length();
        for (int i = 0; i < count; i++) {
            JSONObject imageJson = entries.getJSONObject(i).getJSONObject("im:image");
            // in case you want to get image with height 53
            String imageUrl = imageJson.getJSONObject("0").getString("label");
    
            // String imageUrl = imageJson.getJSONObject("1").getString("label"); height 75
            // String imageUrl = imageJson.getJSONObject("2").getString("label"); height 100
    
            // add urls to the list
            imageUrls.add(imageUrl);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    

    then change your adapter to have a List<String> imageUrls instead of List<ImagesModule> imagesModule and pass the parsed list to the constructor. Finally in your adapter onBindViewHolder() change the picasso code to

    Picasso.with(context).load(imageUrls.get(position)).into(holder.appImage);
    

    hope it helps

    0 讨论(0)
提交回复
热议问题