Hello! I ran into a problem with the offset: the likes of the news are not set correctly. Ie if I like the first news, then it will be placed on the second ...
public class PostAdapter extends RecyclerView.Adapter<PostAdapter.PostViewHolder> { private LayoutInflater mInflater; private int mShowStyle; VKPostArray obj; VKApiPost p; VKApiPhoto vkPhoto; ArrayList<String> imgUrls1; ....... public PostAdapter(Context context, VKPostArray posts, VKApiUser user, int showStyle) { super(); this.obj = posts; this.mainUser = user; this.mInflater = LayoutInflater.from(context); this.mShowStyle = showStyle; ctx = context; } @Override public void onBindViewHolder(final PostViewHolder holder, int position) { p = obj.get(position); holder.textPost.setText(p.text); Linkify.addLinks(holder.textPost, Linkify.WEB_URLS); holder.textPost.setClickable(true); holder.textPost.setMovementMethod(LinkMovementMethod.getInstance()); holder.like1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { setLike("post", "...", p.getId()); Toast.makeText(ctx, "Лайк поставлен", Toast.LENGTH_SHORT).show(); } else { /// }} }); holder.textlikePost.setText("" + p.likes_count); holder.textrepostPost.setText("" + p.reposts_count); SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm"); holder.textDatePost.setText(format.format(new java.util.Date(p.date * 1000))); VKAttachments att = new VKAttachments(); att = p.attachments; int i; imgUrls1 = new ArrayList<>(att.size()); try { for (i = 0; i <= att.size(); i++) { vkPhoto = (VKApiPhoto) att.get(i); imgUrls1.add(vkPhoto.photo_604); } } catch (Exception e) { holder.mNglContent.setImagesData(imgUrls1); }} @Override public int getItemCount() { return obj.size(); } @Override public PostViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (mShowStyle == NineGridImageView.STYLE_FILL) { return new PostViewHolder(mInflater.inflate(R.layout.recycler_item_wall, parent, false)); } else { return new PostViewHolder(mInflater.inflate(R.layout.recycler_item_wall, parent, false)); }} public class PostViewHolder extends RecyclerView.ViewHolder { CardView cv; TextView textPost, news_name, textDatePost, textrepostPost, textlikePost, autor; ImageView repost ; CircleImageView news_ava; CheckBox like1; NineGridImageView mNglContent; private NineGridImageViewAdapter<String> mAdapter = new NineGridImageViewAdapter<String>() { @Override protected void onDisplayImage(Context context, ImageView imageView, String s) { Picasso.with(context).load(s).placeholder(R.drawable.ic_ab_app).into(imageView); } @Override protected ImageView generateImageView(Context context) { return super.generateImageView(context); } @Override protected void onItemImageClick(Context context, int position, List<String> list) { Intent intent = new Intent(context, FullPhoto.class); intent.putStringArrayListExtra(Constants.BUNDLE_BITMAP, new ArrayList(list)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } }; public PostViewHolder(View itemView) { super(itemView); cv = (CardView) itemView.findViewById(R.id.card_view_wall); news_name = (TextView) itemView.findViewById(R.id.news_name); news_ava = (CircleImageView) itemView.findViewById(R.id.news_ava); textDatePost = (TextView) itemView.findViewById(R.id.textDatePost); textPost = (TextView) itemView.findViewById(R.id.textPost); textlikePost = (TextView) itemView.findViewById(R.id.tv_likes_count); like1 = (CheckBox) itemView.findViewById(R.id.iv_like_button); textrepostPost = (TextView) itemView.findViewById(R.id.tv_reposts_count); repost = (ImageView) itemView.findViewById(R.id.iv_repost); mNglContent = (NineGridImageView) itemView.findViewById(R.id.ngl_images); mNglContent.setAdapter(mAdapter); } } public static String setLike(String type, String owner_id, int item_id ) { final String[] res = {""}; VKRequest request = new VKRequest("likes.add", VKParameters.from("type", type, "owner_id", owner_id, "item_id", item_id)); request.executeSyncWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); try { JSONObject jsonObject = response.json.getJSONObject("response"); res[0] = jsonObject.getString("likes"); } catch (JSONException e) { e.printStackTrace(); }} }); return res[0]; }} obj I fill in this way:
VKRequest reqWall = VKApi.wall().get(VKParameters.from(VKApiConst.OWNER_ID, группа, VKApiConst.EXTENDED, 1, VKApiConst.COUNT, 100, "text")); reqWall.setPreferredLang("ru"); reqWall.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); JSONObject jsonObject = response.json; String owner = null; try { owner = (((JSONObject) ((JSONArray) ((JSONObject) jsonObject.get("response")).get("items")).get(0)).getString("owner_id")); } catch (JSONException e) { e.printStackTrace(); } posts = new VKPostArray(); try { posts.parse(response.json); } catch (JSONException e) { e.printStackTrace(); } try { JSONArray array = ((JSONArray) ((JSONObject) jsonObject.get("response")).get("groups")); } catch (JSONException e) { e.printStackTrace(); } try { VKApiPost post = posts.get(0); } catch (Exception e) { }