Android: SortedList with duplicates

后端 未结 6 992
栀梦
栀梦 2021-02-19 21:58

I have some problems understanding RecyclerViews SortedList.

Lets say I have a very simple class only having a very simple class holding data:<

6条回答
  •  既然无缘
    2021-02-19 22:02

    You can check if the object already exist in the sorted list by doing this.

    if (sortedList.indexOf(item) == -1) 
    {
        sortedList.add(item);  //Item still does not exist because index is -1
    } 
    else 
    {
        sortedList.updateItemAt(sortedList.indexOf(item), item);
    }
    

提交回复
热议问题