如何从这段代码中获取值time
val TAG = MainActivity::class.java.name
TrueTimeRx.build()
.initializeRx("time.google.com")
.subscribeOn(Schedulers.io())
.subscribe({ time ->
Log.v(TAG, "TrueTime was initialized and we have a time: $time") },
{ throwable -> throwable.printStackTrace() }
)并将其放入下面的代码中
helloWorld=findViewById(R.id.helloWorld)
val newTime=getString(R.string.hello, time)
helloWorld.text=newTime如何从代码的第一部分获取time并将其放入第二部分
上面的代码是用onCreate()编写的
如果这很重要的话我有这个
internal lateinit var helloWorld: TextView发布于 2019-11-10 20:55:15
该值将在订阅方块中提供:
TrueTimeRx.build()
.initializeRx("time.google.com")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ time ->
Log.v(TAG, "TrueTime was initialized and we have a time: $time")
val newTime = getString(R.string.hello, time)
helloWorld.text = newTime
}, { throwable -> throwable.printStackTrace() }
)请注意,您必须使用observeOn(AndroidSchedulers.mainThread())才能修改块内的视图内容。
https://stackoverflow.com/questions/58788392
复制相似问题