In Android project implemented Android Architecture component successfully as per developer guideline but the problem is we can observe full object change using LiveData
mQueViewModel.getLiveQuestion().observe(this, new Observer<Question>() {
@Override
public void onChanged(@Nullable Question question) {
Log.i(TAG, "onChanged: ");
setQuestionDetails();
}
});
Any single object property change fire OnChanged this cause to set all data again to UI So is there any way to implement property change like onDescriptionChange, onImageChange ...
To do that you could use the ViewModel to break the data in smaller pieces. Something like this should work:
private LiveData<Question> questions;
private MediatorLiveData<String> description;
public MQueViewModel() {
description = new MediatorLiveData<>();
description.addSource(questions, new Observer<Question>() {
@Override
public void onChanged(@Nullable Question question) {
if (question == null) return;
if (!question.description.equals(description.getValue())) {
description.setValue(question.description);
}
}
});
}
and have than have your UI subscribe to description. Add similar MediatorLiveData to any other property change u need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With