I'm trying to update an custom Dialog in real time So far I have the custom dialog working and looking how I want
The problem is that the dialog shows with no problem with the text "Loading...", it freezes for the amount of ms (from the sleep) and when its over it changes to "3"
I hope someone can give a little help, thanks!
Code
package com.slimakoi.myfirstapp
import android.annotation.SuppressLint
import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
class TrackerActivity : AppCompatActivity() {
@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_tracker)
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().permitAll().build())
val dialog = Dialog(this)
dialog.setContentView(R.layout.notification)
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val nMsg = dialog.findViewById<TextView>(R.id.notificationMessage)
val nImg = dialog.findViewById<ImageView>(R.id.notificationImage)
nMsg.text = "Loading..."
nImg.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.error))
dialog.show()
Handler(Looper.getMainLooper()).post {
runOnUiThread {
for (i in 0 until 5) {
nMsg.text = "1"
SystemClock.sleep(500)
nMsg.text = "2"
SystemClock.sleep(500)
nMsg.text = "3"
SystemClock.sleep(500)
}
}
}
}
}