CountryCodePickerProject
CountryCodePickerProject copied to clipboard
How to use with databinding (using livedata instead observable)
Please how can I use with databinding to get selectedCountryCodeWithPlus using LiveData instead ObservableField.
#250 Advance thanks!
I guess if selectedCoutryCodeWithPlus is exposed as property variable, then it will can be used with the livedata, right?
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
This is not getting invoked the 1st time( for the default selected country code)