Zibran
Zibran

Reputation: 103

How to show dates on the basis of comparing two different array lists inside a RecyclerView?

I am trying to show Ticks(green tick as in the screenshot) on comparing two ArrayList in a recyclerView. enter image description here

The first ArrayList (List1) contains all the dates:

List1 = [2022-02-21,2022-02-22,2022-02-23 2022-02-24, 2022-02-25, 2022-03-10]

The second ArrayList (List2) contains only the dates which upon matching with List1 will enable the green tick:

List2 = [2022-02-21,2022-02-22]

This is how I am comparing it in my Adapter class :

   for (int j = 0; j < List1.size(); j++) {
            if (List1.get(j).trim().equalsIgnoreCase(List2.get(position).trim())) {
                holder.greenTick.setVisibility(View.VISIBLE);

            } else {
                holder.greenTick.setVisibility(View.GONE);
            }

        }

The problem is that all the Ticks are visible. The matching of ArrayList is not working.

Upvotes: 1

Views: 42

Answers (1)

Adinia
Adinia

Reputation: 3731

If you use List1 to show all the dates in the recycler, then position in your code is probably the adapter item position for each date square you got from List1. You then want to compare each item with the values in List2 to know if you should show the tick or not.

So the comparison should be something like

for (int j = 0; j < List2.size(); j++) {
            if ("Adapter item at position".equalsIgnoreCase(List2.get(j).trim())) {
                holder.greenTick.setVisibility(View.VISIBLE);
            } else {
                holder.greenTick.setVisibility(View.GONE);
            }

        }

Upvotes: 1

Related Questions