0

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 ?

Molly
  • 1,887
  • 3
  • 17
  • 34
hema
  • 1
  • 4

2 Answers2

0

Make adapter with multiple view holder and bind specific layout as first as your condition multiple item recyclerview

  • 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