mercredi 23 octobre 2019

Randomize LiveData

How can I randomize a LiveData> in a ViewModel and display the results in my RecyclerView? I was thinking I could do a Collection.shuffle(Arrays.asList(myList)), but I don't believe this changes the order of the objects in the LiveDatalist.

MyFragment

....
public void RandomizeListOrder() {
    mMainActivityViewModel.setRandomOrder();
    adapter.notifyDataSetChanged();
}

ViewModel

private LiveData<List<StudentEntity>> mStudentList

public void setRandomOrder() {
    Collection.shuffle(Arrays.asList(mStudentList));
}



Aucun commentaire:

Enregistrer un commentaire