线程UI更新报错:Only the original thread that created a view hierarchy can touch its views.

当我们在线程里面更新UI的时候会报错:Only the original thread that created a view hierarchy can touch its views.
如下面的代码:直接在UDP发送线程里面更新UI,就会报错,报错提示如下。
线程UI更新报错:Only the original thread that created a view hierarchy can touch its views.
线程UI更新报错:Only the original thread that created a view hierarchy can touch its views.
这里的解决办法是把UI更新放到Handler里面。所以把上述代码的UI更新部分修改为如下图所示。

线程UI更新报错:Only the original thread that created a view hierarchy can touch its views.