问题描述
我在activity_receive_code.xml
文件中创建一个ID为ReceivedCodeTxt的textView,然后创建一个名称为SMSReceiver.kt
的新kotlin文件...现在,我想在{{1}中为textView设置文本}文件,但我不知道如何访问它并更改另一类的文本。
SMSReceiver.kt
}
解决方法
您可以通过使用界面来实现
在您的SMSReceiver.kt类中创建一个接口
class SMSReceiver.kt(val callback:ICallback) {
interface ICallback{
fun updateUI(value:String)
}
fun doSomething() {
// your operations to perform some task. then call this
callback.updateUI(/*Pass your data which you want to set to your textview*/ "")
}
}
class ActivityReceive: SMSReciever.ICallback {
override fun updateUI(value:String) {
//set the data which you got from SMSReceiver class
textview.text = value
}
}