I want to contact get'er in the nested model.

I will explain, in my fragment there is:

List<Control> controlList = new ArrayList<>();

And already in the Control model is:

 private List<ImageUpload> imageUploads = new ArrayList<>(); 

And therefore in ImageUpload I have a parameter

 private String url; public String getUrl() { return url; } 

I try to get the url in the fragment as follows:

 controlList.get(position).getImageUploads().getUrl(); 

but getUrl is highlighted in red ... (although in theory it should not. Please tell me how to fix the error.

Model ImageUploads

 @SerializedName("success") @Expose private Boolean success; @SerializedName("output_metadata") @Expose private OutputMetadata outputMetadata; @SerializedName("handler") @Expose private Integer handler; @SerializedName("id") @Expose private String id; private List<VideoUpload> videoUploads = new ArrayList<>(); @SerializedName("url") @Expose private String url; 
  • And what position in the nested list do you need to get? or the entire nested list? - pavlofff
  • @pavlofff sorry, didn’t quite understand the question. The position of the element in the list - each element has its own link and you need to get it. - Inkognito
  • You have another collection ( imageUploads ) in the controlList collection, there are several elements (links) - which one do you need (or all)? - pavlofff
  • @pavlofff just getUrl - Inkognito
  • one
    You have several elements in the imageUploads list .. several, you try to treat as if there is not a list, but one variable, and you have a list in the list - pavlofff

1 answer 1

You getImageUploads() returns a list. It should be something like this:

 controlList.get(position).getImageUploads().get(imagePosition).getUrl(); 
  • imagePosition in the role of what here in general acts? updated question (added model), please take a look - Inkognito
  • @Inkognito imagePosition here acts as an element position in a nested list, something that I can’t get from you in any way what position you need there - pavlofff
  • @pavlofff position of all added items, there is no specific. - Inkognito
  • @pavlofff let's say I got the url data, how do I add it later? following the example of how I added the picture controlList.get (position) .getImageUploads (). add (0, imageUpload); - Inkognito