how to sort/filter recycler view card view and show that card view on top of all card view in android. I have some boolean flag as true on check of true I need to show that particular card on top as 1st card view then others below and how to achieve this ?
Asked
Active
Viewed 170 times
0
-
Should the other items be shown when a new sort query is entered? What is this new query, is it only a Boolean or is it string based sort? – Haroun Hajem Mar 26 '19 at 17:42
-
yes other item should be shown below , only boolean – hema Mar 26 '19 at 17:46
2 Answers
0
Make adapter with multiple view holder and bind specific layout as first as your condition multiple item recyclerview

Ahmad Sheraz
- 1
- 1
-
I have singel api response from that response which ever item flag I get true that need to shown on top and rest below – hema Mar 26 '19 at 17:43
-
how to filter out that particular card view the one with boolean true and show on top – hema Mar 26 '19 at 17:44
0
Add the method inside the adaptre, hope it helps:
public void sortItem() {
ArrayList<Item> items = new ArrayList<>();
Item top =null ;
for(Item item : data){
if(!item.isTop){
items.add(item);
}else{
top = item;
}
}
if(top!=null){
items.add(0, top);
}
data.clear();
data.addAll(items);
adapter.notifyDataSetChanged();
}
class Item{
public Boolean isTop;
}
if You want get sorted list right away You can sort the list and submit yo recycler view adaper inside the activity:
ArrayList<Item> items = new ArrayList<>();
Item top =null ;
for(Item item : data){
if(!item.isTop){
items.add(item);
}else{
top = item;
}
}
if(top!=null){
items.add(0, top);
}
yourAdapter.submitList(items)

Serg Burlaka
- 2,351
- 24
- 35
-
-
@hema if you want get sorted list you can sort the list and submit yo recycler view adaper – Serg Burlaka Mar 27 '19 at 11:30
-