Move RecyclerView clicked item to the top

后端 未结 2 1405
情歌与酒
情歌与酒 2021-01-14 09:35

I have a recyclerView with n items. Each item is expandable onCLick of it. I want my item to expand as well as move to the top onCLick. Suppose if I click third item then it

2条回答
  •  不要未来只要你来
    2021-01-14 09:51

    You can do like this way: Create one method in adaptor as below.

     public void swapeItem(int fromPosition,int toPosition){
         Collections.swap(arrayList, fromPosition, toPosition);
         notifyItemMoved(fromPosition, toPosition);
     }
    

    now on item click you can use like this way.

    swapeItem(9,0); // here 9 is a clicked item position and 0 means at top of the list.
    

提交回复
热议问题