Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I make it where I am notified when a custom thread is complete so I can update an EditText?

 
Eric Sweeten
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I first remove all views from the layout and add the EditText. The EditText is going to contain a lot of text, generated during the thread. At the end of the Thread, I want the EditText's text to be updated, but I keep getting an error.





This is the exception I'm getting:

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

How can I make it where I know when the BackgroundCalc thread is done so I can update the text in editTextReport?
 
Tim Moores
Bartender
Posts: 3137
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the error message says, you can't modify UI objects from a background thread, you need to do that on the UI thread. Rather than extending Thread, I prefer to extend AsyncTask, which has a method to handle stuff on the UI thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic