所以正如我告诉你的,我想到了具有自定义逻辑的回收器视图! 它起作用了!!
根据要求,我想要大小为 5 的新列表 所以,我有自己的逻辑
fun main() {
var l: ArrayList<Int?> = arrayListOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
newList(l, 5)
}
fun newList(list: ArrayList<Int?>, selected: Int = 1): ArrayList<Int?>
{
var newList: ArrayList<Int?> = arrayListOf()
if (list.size <= 5) {
return list
}
if (selected == 1 || selected == list.size || list.size - selected == 1) {
newList = arrayListOf(1, 2, null, list.size - 1, list.size)
} else if (selected - 1 >= 2) {
newList = arrayListOf(1, null, selected)
if (list.size - selected >= 2) {
newList.add(null)
newList.add(list.size)
}
} else if (selected - 1 == 1) {
newList = arrayListOf(1, selected, null, list.size - 1, list.size)
}
return newList
}