I have several items in a RecyclerView
and each item has a long
value saved with it. I'm using FastAdapter as the adapter for my RecyclerView
.
Suppose there are 7 items in the RecyclerView
with the long values: 11122
, 12321
, -98811
, 8870
, -88009
, 3398
, and -22113
.
So, what I want to do is, I want to filter the items based on the above given long values using this logic:
if (l <= 1000) {
// show items with long value <=1000
} else if (l > 1000) {
// show items with long value >1000
}
I tried various things, but nothing worked out.
UPDATE 1: Items here are a sort of different data stored in CardView
and then shown in RecyclerView
. Each card contains different data, one of which are the above given long
values. I want to filter the data based on these long
values stored in each card based on the logic given above.
Please help me with this issue and suggest some algorithm or code with which I can achieve this.
With the amount of information given I can only suppose
l
is a foreign selector value which controls the items to be displayed inside theRecyclerView
. Comment below if this is not the case, I will try to correct my answer.I recommend implementing a custom
ViewAdapter
, sending in the list of items and the selector variablel
using respective methods:Also, I have never used FastAdapter, but I suppose there must be some methods to override if you extend its class.
Update
Since, you are facing problems understanding the basics of using a
ViewAdapter
, I would recommend learning and implementing a customViewAdapter
before using any library. Here's a extensive tutorial for how to implementViewAdapter
for RecyclerView.Now, after you have implemented the ViewAdapter you can use my piece of code to filter out cards. Basically, what the code is doing is saving a list of all the required data inside
mItemList
, whilemDisplayList
is a list storing the items to be displayed, which is updated every-timemAboveThousand
, which stores the user preference of above or below 1000, is set. Now thismDisplayList
must be used to inflate data inside the RecyclerView.