如何使用数据绑定获取在自动完成的textview中键入的文本并在viewmodel中获取文本?

 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!!
   }
lufangfeiok 回答:如何使用数据绑定获取在自动完成的textview中键入的文本并在viewmodel中获取文本?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3067191.html

大家都在问