Writing to the UI with MonoDroid using RunOnUIThread

I've been pulling my hair out over the past day or so trying to update the UI in my test app.  I was having problem after problem.  I finally got down to my base problem.  I could not write out to my TextView.  WTF could be causing that?  I can write to my UI in other parts of my app.  This is pure craziness.  I thought long and hard and nothing was coming to me.  Wait, the light bulb went on.  I am in the wrong thread.  Great, how do I write in the correct thread?  MonoDroid supports the entire AsyncTask set of objects, but this seemed like overkill.  I was reading and came across RunOnUIThread().......Bing..........The lightbulb has been invented...BlueStar Airlines (oh wait, wrong context). Anyway, here is what I needed:

this.RunOnUiThread(() => TextViewControl.Text = "Hello World");

Enjoy!!!!!!!  Remember kiddies, running on the main ui for off device operations is bad, not as bad as crossing the streams bad, but bad as in trying to drive on a flat tire bad. It won't kill you, but it does keep you from getting anywhere.

No Comments