如何随机化 LiveData<list<StudentEntity>>
在 ViewModel
并将结果显示在我的RecyclerView
中?我想我可以做一个
Collection.shuffle(Arrays.asList(myList))
但我不相信这会改变 LiveDatalist 中对象的顺序。
我的 fragment
....
public void RandomizeListOrder() {
mMainActivityViewModel.setRandomOrder();
adapter.notifyDataSetChanged();
}
View 模型
private LiveData<List<StudentEntity>> mStudentList
public void setRandomOrder() {
Collection.shuffle(Arrays.asList(mStudentList));
}
最佳答案
您可以使用实时数据转换来操作实时数据。
val transformedLiveData = Transformations.map(
yourActualLiveData) { //Shuffle logic here }
关于java - 随机化 LiveData<List<name>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58534683/