I've tried some examples with viewmodels and databinding using BehaviorSubjects and other Observables. Now I have real (data class) object in Kotlin, which holds most of the state. It is basically pojo, but independent from viewmodel and has no observables. I don't understand how can I bind this automatically to ex. TextView in android without creating external observable variables in viewmodel and some boilercode. I'd think this is something very common in mvvm pattern. Or am I missing something totally?
Asked
Active
Viewed 421 times
0
-
You should implement [binding adapters](https://developer.android.com/topic/libraries/data-binding/binding-adapters) – Sanlok Lee Jun 25 '19 at 00:51
1 Answers
0
Using Google's ViewModel
component you should bind your view to the ViewModel class only. And your ViewModel class should take care of pulling the data from somewhere (from interactors, for example).
In your case, you can have Observable in the ViewModel which will pull the data from Kotlin class you mentioned. And your view will get this data from ViewModel's observable directly.
If I don't understand you correctly - please provide your code with more details :)

Vadim
- 141
- 4
-
Yes, but the data you get is for example model or data class - with properties. I'd like to do stuff with that property, for example to bind it to view. – K.H. Jun 26 '19 at 16:39
-
Well, if taliing about "canonic" updating UI from the model - you can use RxBindings (if preferr Rx): https://github.com/JakeWharton/RxBinding. Or LiveData provided by Google in Architectural Components: https://developer.android.com/topic/libraries/architecture/livedata – Vadim Jun 26 '19 at 16:58