繁体   English   中英

回收器适配器项目错误

[英]Recycler Adapter item bug

我正在尝试创建一个像 instagram 这样的评论页面,但我遇到了一个荒谬的错误;

每个评论行都有一个 recyclerview 并且用户单击“显示回复”按钮我使 Recyclerview 可见但在 10-11 个项目之后,该项目的 recyclerview 也可见。

我知道我的英语很糟糕,但我需要帮助。

holder.replyCount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(main,"sdf",Toast.LENGTH_LONG).show();
            new Comment().getCommentResponse(getCommentModels.get(position).getId(), new IMainResponse() {
                @Override
                public <T> void Succsess(Response<T> _response) {
                    getCommentModel = (List<getCommentModel>) _response.body();
                    AdapterComment adapterComment = new AdapterComment(main, getCommentModel);
                    
                    holder.recyclerView.setVisibility(View.VISIBLE);
                    holder.recyclerView.setAdapter(adapterComment);
                    holder.recyclerView.setHasFixedSize(true);
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(main);
                    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    holder.recyclerView.setLayoutManager(linearLayoutManager);
                }

                @Override
                public void Error(ErrorModel _eresponse) {

                }
            });
        }

    });

在 model class 中创建 boolean 以跟踪可见性

if (getCommentModels.get(position).isVisible()) {
  holder.recyclerView.setVisibility(View.VISIBLE);
} else {
  holder.recyclerView.setVisibility(View.GONE);
}
holder.replyCount.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
    getCommentModels.get(position).setVisible(!getCommentModels.get(position).isVisible());
    notifyItemChanged(position);
    new Comment().getCommentResponse(getCommentModels.get(position).getId(), new IMainResponse() {
      @Override
      public <T> void Succsess(Response<T> _response) {
        getCommentModel = (List<getCommentModel>) _response.body();
        AdapterComment adapterComment = new AdapterComment(main, getCommentModel);

        holder.recyclerView.setAdapter(adapterComment);
        holder.recyclerView.setHasFixedSize(true);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(main);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        holder.recyclerView.setLayoutManager(linearLayoutManager);
      }

      @Override
      public void Error(ErrorModel _eresponse) {

      }
    });
  }

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM