简体   繁体   中英

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. 在此处输入图像描述

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.

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);
            }

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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