layout.xml
How to get the text which typing in autcomplete textview using databinding and get text in viewmodel?
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:id="@+id/pickup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@null"
android:hint="@string/from"
android:maxLength="15"
android:onTextChanged="@{SpotViewmodel.onPasswordTextChanged}"
android:padding="5dp"
android:singleLine="true" />
this is the viewmodel class i want to send the text which i got from autocomplete textview to api.how to implement two way binding in viewmodel class as most the examples are covered with base observables
SpotViewmodel.kt
SpotViewmodel类:ViewModel(){ var data:MutableLiveData?= null val first = MutableLiveData() var value:String?=“ val apikey:String =“ u9fyiuc8t7” var autoRepository:ServiceGenerator = ServiceGenerator()。getInstance() 有趣的init(){ if(data!= null){ 返回 } 数据= autoRepository.getStationresponse(值!!,apikey) } fun onPasswordTextChanged(s:CharSequence,start:Int,before: 整数,计数: Int){
Log.e("eeeee","" + s.toString()) value = s.toString() } fun getNewsRepository(): MutableLiveData<Autocompleteresponse> { return data!! }