Firstly i might not actually be understanding what mutable live data is correctly.
i get data from room using live data and then show it to the UI, it is a question with answers, so at the end of the question i would like to update the database with correct answers, the time it took etc etc.
I cannot work out how to use Mutable live data as there is next to no useful information on it or i'm incredibly stupid!
So firstly, can i actually update the database with mutable live data?
if so how? (i don't like asking this but i am a really stumped)
Dao
@Query("SELECT * FROM question_table WHERE :id = uoe_id")
LiveData<Question> getQuestionLiveData(int id);
Repo
public LiveData<Question> getQuestionLiveData(int id) {
return questionDao.getQuestionLiveData(id);
}
ViewModel
public LiveData<Question> getQuestionLiveData(int id) {
return questionRepository.getQuestionLiveData(id);
}
And then observing it in the View
viewModel.getQuestionLiveData(packageId).observe(getViewLifecycleOwner(), new Observer<com.questionTest.practice.Model.Question>() {
@Override
public void onChanged(com.questionTest.practice.Model.QuestionQuestion question) {
Do stuff here////
}
}
});
The next part is where i'm not sure. i added this in the view model
MutableLiveData mutableLiveData = new MutableLiveData();
and then tried to assign the this to the question
mutableLiveData = (MutableLivedata) getQuestionLiveData(id);
so i could use update the values but this throws an Casting error.
Im either missing something or i cannot do this so any help will be welcomed thanks