Home > Blockchain >  Recycler view item disappearing
Recycler view item disappearing

Time:12-30

I have an issue with recycler view. I implemented a collapse logic as you can see on the code below. But when I close the second item the view disappear as you can see on the video. What am I doing wrong. Please assist. Thanks

 public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

    View v = LayoutInflater.from(viewGroup.getContext())
            .inflate(R.layout.report_layout, viewGroup, false);

    final ReportHolder holder = new ReportHolder(v);

    //hide half of the view
    holder.linearLayout.setVisibility(View.GONE);

    holder.tvPrintReceipt.setVisibility(View.INVISIBLE);

    holder.tvClose.setOnClickListener(v1 -> {
        TransitionManager.beginDelayedTransition(viewGroup, new AutoTransition());
        holder.linearLayout.setVisibility(View.GONE);
        holder.tvViewRecords.setVisibility(View.VISIBLE);
    });

    holder.tvViewRecords.setOnClickListener(v2 ->{
        TransitionManager.beginDelayedTransition(viewGroup, new AutoTransition());
        holder.linearLayout.setVisibility(View.VISIBLE);
        holder.tvViewRecords.setVisibility(View.GONE);
    });

    return holder;
}

CodePudding user response:

In order to not have problems with this you should set the visibility of your entire item to GONE. itemView.setVisibility(View.GONE); or view.setVisibility(View.GONE);

Also check this thread for more information How to hide an item from Recycler View on a particular condition?

CodePudding user response:

The reason of this problem is that you wrote your logic in onCreatViewHolder which will be called once and you have to move it to onBindViewHolder which will be called per each item in RecyclerView. This will solve your issue. Now, clicking on each item, makes change on all items in the list.

  • Related