Help to bring ArrayList images from VC. I receive one picture, and ArrayList - I do not know how.

I get this:

 public class RecyclerAdapterWall extends RecyclerView.Adapter<RecyclerAdapterWall.ViewHolder> { Context ctx; String owner_id; VKPostArray obj; Picasso picasso; private long longDate; public RecyclerAdapterWall(Context ctx, VKPostArray posts) { this.obj = posts; this.ctx = ctx; } public RecyclerAdapterWall(Context ctx, VKPostArray posts, String owner_id) { this.obj = posts; this.ctx = ctx; this.owner_id = owner_id; } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_wall, parent, false); ViewHolder viewHolder = new ViewHolder(v); return viewHolder; } @Override public void onBindViewHolder(ViewHolder holder, final int position) { holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { } }); VKApiPost p = obj.get(position); try { VKAttachments att = new VKAttachments(); att = p.attachments; VKApiPhoto photo = (VKApiPhoto) att.get(0); holder.imageWall.setVisibility(View.VISIBLE); holder.imageWall.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View arg0) { } }); holder.textPost.setText(p.text); holder.news_name.setText(p.post_type); holder.textlikePost.setText(" " + p.likes_count); holder.textrepostPost.setText(" " + p.reposts_count); java.util.Date time = new java.util.Date((long) p.date * 1000); holder.textDatePost.setText(String.valueOf(time)); picasso.with(ctx).load(photo.photo_604).into(holder.imageWall); //picasso.with(ctx).load().into(holder.news_ava); } catch (Exception e) { } } @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); } @Override public int getItemCount() { return obj.size(); } public static class ViewHolder extends RecyclerView.ViewHolder{ Context ctx; CardView cv; TextView textlikePost; TextView textrepostPost; TextView textDatePost; TextView news_name; TextView textPost; ImageView imageWall, news_ava, like, repost; public ViewHolder(final View itemView) { super(itemView); cv = (CardView) itemView.findViewById(R.id.card_view_wall); news_name = (TextView) itemView.findViewById(R.id.news_name); textDatePost = (TextView) itemView.findViewById(R.id.textDatePost); textPost = (TextView) itemView.findViewById(R.id.textPost); imageWall = (ImageView) itemView.findViewById(R.id.imageWall); news_ava = (ImageView) itemView.findViewById(R.id.news_ava); textlikePost = (TextView) itemView.findViewById(R.id.tv_likes_count); textrepostPost = (TextView) itemView.findViewById(R.id.tv_reposts_count); like = (ImageView) itemView.findViewById(R.id.iv_like); repost = (ImageView) itemView.findViewById(R.id.iv_repost); }} public void clear() { obj.clear(); notifyDataSetChanged(); } } 
  • 2
    uh-uh ... To take not by index 0, but to run a cycle through all the pictures? ... - YuriySPb
  • for (i = 0; i <att.size (); i ++) {So what? - sviter-pro
  • one
    Like, yes. You can still do this: for (VKApiPhoto photo : att) {...} - Yuriy SPb
  • one
    Thank you ... helped ... - sviter-pro
  • one
    List <VKApiPhoto> list = new ArrayList <> (); list.add (photo); - Yuriy SPb

1 answer 1

Strange, I did this:

 VKAttachments att = new VKAttachments(); att = p.attachments; for(i = 0; i < att.size(); i++){ VKApiPhoto photo = (VKApiPhoto) att.get(i); List<VKApiPhoto> mSmallPhotoUrls = new ArrayList<>(); mSmallPhotoUrls.add(vkPhoto); List<String> imgUrls = new ArrayList<>(mSmallPhotoUrls.size()); imgUrls.add(vkPhoto.photo_604); } 

And imgUrls all comes exactly one picture .... help me figure it out

  • one
    Every time you create a new list with photos / links. So you have one element in length. Take out the creation of a list outside the cycle, and fill them in a cycle - YuriySPb
  • you can show!!! I’m already having a good day for this .... I have nothing to think about .... I ’m thankful in advance - sviter-pro
  • aaaaaa .... thanks a lot !!! it turned out ... - sviter-pro
  • And here's another question !!! Here is the answer, how one picture is made and it corresponds to this news !!! And if I endure the creation of a list of pictures on the limits of the cycle, then they begin to be anywhere !!! Is this corrected? - sviter-pro
  • what size should come attachment with VC? (I'm talking about size () ???? example: vkPhoto = (VKApiPhoto) att.get (0);) - sviter-pro