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
  • 74
  • 1
  • 13

1 Answers1

0

You cannot use AsyncTask to alter UI elements!

Use a TimerTask

Darshan
  • 4,020
  • 2
  • 18
  • 49
  • 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