1

How to get value time from this code

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() }

    )

and put it in this code

helloWorld=findViewById(R.id.helloWorld)

val newTime=getString(R.string.hello, time)
helloWorld.text=newTime

how to take time from the first part of the code and to put it in the second

code above is in onCreate()

and if it's important i have this

internal lateinit var helloWorld: TextView
Taseer
  • 3,432
  • 3
  • 16
  • 35

1 Answers1

1

The value will be available in the subscriber block:

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() }
    )

Note that you have to observeOn(AndroidSchedulers.mainThread()) to be able to modify View contents inside the block.

Egor
  • 39,695
  • 10
  • 113
  • 130