Hello, how can we pass EditText's value to another...
# android
h
Hello, how can we pass EditText's value to another class (not activity/fragment) using MVVM?
😶 3
s
I'm afraid that's not enough details to work from. Which other class are you wanting to pass the value to? And where does that class sit in your architecture?
h
@Sam thanks for your reply. I used OkHttpClient in another class, and I want to pass EditText's value to OkHttpClient's body which is located in another class (not activity/fragment)
s
share the same ViewModel between those 2 fragments
h
@Salva Martin thanks for your reply. I don't use 2 fragments.
s
I would recommend reading this https://medium.com/swlh/repository-pattern-in-android-c31d0268118c OkHttpClient should be nowhere near the fragment as you said, it should be in a different class. I'd recommend reading that article and passing the edit text value through your ViewModel up into a repository class which can then make your network request. (as an aside, I'd also recommend using retrofit rather than using OkHttp directly https://square.github.io/retrofit/)
💯 3