0

I want to update a textview in a fragment every 1 second.It is crashing after 1 second. Any help. " android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views."

   doAsync {
                timer.scheduleAtFixedRate(1000, 1000)
      { timing_of_task.text = (Date() - task!!.tasktimer!!.startTime).formatted() }

                    } 
EliodeBeirut
  • 64
  • 11

1 Answers1

0

You cannot use AsyncTask to alter UI elements!

Use a TimerTask

DarShan
  • 2,558
  • 2
  • 14
  • 38
  • timer.schedule(object : TimerTask() { override fun run() { activity!!.runOnUiThread { timing_of_task.text = (Date() - task!!.tasktimer!!.startTime).formatted() } } }, 1000, 1000) – EliodeBeirut Sep 13 '18 at 12:35