Answer the question
In order to leave comments, you need to log in
I created a class that extends LiveData, why can't I apply ExampleClass.value=edText.text.toString in MainActivity?
class MyLiveData: LiveData<String>() {
}
class MainActivity : AppCompatActivity() {
val myLiveData=MyLiveData()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn_Ok.setOnClickListener {
myLiveData.value = edText.text.toString() // ошибка
Log.e("//////////////////","${myLiveData.value}")
}
}
}
fun getValue(s:String){
value=s
}
Answer the question
In order to leave comments, you need to log in
Because it is necessary to read errors and the documentation.
setValue is a protected method. It can only be called from subclass methods, not from outside.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question