0

实际上我想以这种方式对我的列表进行排序:我有一个这样的 mutableList

noteList = mutableListOf<NoteDataHolder>().apply {
        notes.forEach {
            add(NoteDataHolder(it))
        }
}

想象一下NoteDataHolderId我想以此对我的列表进行排序Id

我的清单是这样的:[ {id=1}, {id=2}, {id=3}, {id=4} ]

当我像这样过滤我的列表时:noteList.filter { it.note?.bookId == 4 }

我只收到[ {id=4} ]

item4最后,我想像这样得到所有物品[ {id=4}, {id=1}, {id=2}, {id=3} ]

4

1 回答 1

3

看起来你需要这样的东西:

fun reorderItems(input: List<NoteDataHolder>, predicate: (NoteDataHolder) -> Boolean): List<NoteDataHolder>{
    val matched = input.filter(predicate)
    val unmatched = input.filterNot(predicate)

    return matched + unmatched
}

用来:

noteList = reorderItems (noteList!!) {it.note?.bookId == 4}
于 2020-01-15T14:27:22.320 回答