moayed ayasaa moayed ayasaa - 1 year ago 120
JSON Question

Parsing data from Json as a collection of image to Picasso

I tried to parse a collection of image to

library but i cannot make it work

Note : i dont have any error but not working
Here's Json data a link

My module

public class ImagesModule

public ArrayList getListTest() {
return listTest;

public void setListTest(ArrayList listTest) {
this.listTest = listTest;

ArrayList listTest = new ArrayList( );


this is the Adapter`

public class ImageViewAdapter extends RecyclerView.Adapter<ImageViewAdapter.ViewHolder> {
List<ImagesModule> imagesModules;
Context context;

public ImageViewAdapter(List<ImagesModule> imagesModules, Context context){
this.imagesModules = imagesModules;
this.context = context;}
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from( parent.getContext() ).inflate( R.layout.imageitem, parent,false );
ViewHolder viewHolder = new ViewHolder( v );

return viewHolder;}
public void onBindViewHolder(ViewHolder holder, int position) {
final ImagesModule imagesModule = imagesModules.get( position );
public int getItemCount() {
return imagesModules.size();
class ViewHolder extends RecyclerView.ViewHolder {
public android.widget.ImageView appImage;
public ViewHolder(View itemView) {
super( itemView );
appImage = (android.widget.ImageView) itemView.findViewById(;

and this is the fragment

public class ImageViewFragment extends Fragment {
List<ImagesModule> imagesModules;

List<ImagesModule> imagesModule;
RecyclerView AppRecyclerView;
RecyclerView.Adapter imageRecyclerViewadapter;
String jsonUrl = "";
RequestQueue requestQueue;
private RecyclerView.LayoutManager mLayoutManager;
public ImageViewFragment() {
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_image_view, container, false);
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
AppRecyclerView = (RecyclerView) getView().findViewById(;
imagesModule = new ArrayList<>();
imagesModules = new ArrayList<>();
public void JsonAppShowData() {
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( jsonUrl, new Response.Listener<JSONObject>() {
public void onResponse(JSONObject response) {
try {
ImagesModule imagesModule = new ImagesModule();

JSONArray jsonArray = response.getJSONObject("feed").getJSONArray("entry");
for (int i = 0; i < jsonArray.length(); i++) {
JSONArray imageArray = response.getJSONObject("feed").getJSONArray("entry").getJSONObject(i).getJSONArray("im:image");
for (int j =0; j < imageArray.length(); j++) {
ArrayList listTest = new ArrayList( );
String image = imageArray.getJSONObject(j).getString("label");

imageRecyclerViewadapter = new ImageViewAdapter(imagesModules,getContext());
} catch (JSONException e) {e.printStackTrace();
}}}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Log.e( "LOG", error.toString() );}});
requestQueue = Volley.newRequestQueue(getContext());
mLayoutManager = new GridLayoutManager(getContext().getApplicationContext(),3);

Answer Source

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
} catch (JSONException e) {

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


hope it helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download