CountryCodePickerProject icon indicating copy to clipboard operation
CountryCodePickerProject copied to clipboard

How to use with databinding (using livedata instead observable)

Open Makinul opened this issue 6 years ago • 3 comments
trafficstars

Please how can I use with databinding to get selectedCountryCodeWithPlus using LiveData instead ObservableField.

#250 Advance thanks!

Makinul avatar Jul 22 '19 10:07 Makinul

I guess if selectedCoutryCodeWithPlus is exposed as property variable, then it will can be used with the livedata, right?

hbb20 avatar Aug 04 '19 16:08 hbb20

object CountryPickerBindings { private const val TAG = "CountryPickerBindings" /** * binding adapter to get selected Country */ @JvmStatic @BindingAdapter("selectedCountry") fun selectedCountry(ccp: CountryCodePicker, results: MutableLiveData<String>) { ccp.setOnCountryChangeListener { with(ccp.selectedCountryCodeWithPlus) { Log.d(TAG, "Returning selected code: $this") results.postValue(this) } } } }

and in the xml: app:selectedCountry="@{viewModel.selectedCountry}"

where selectedCountry is a Mutable Live Data inside the view model

grayhatdevelopers avatar Mar 19 '20 13:03 grayhatdevelopers

This is not getting invoked the 1st time( for the default selected country code)

jimmy-jose avatar Aug 04 '20 06:08 jimmy-jose