xamarin.android Android.Util.AndroidRuntimeException Message=Only the original thread that created a view hierarchy can touch its views.

Android.Util.AndroidRuntimeException
Message=Only the original thread that created a view hierarchy can touch its views.

 

 

 

 

错误产生原因,未在UI线程改变UI,导致出错。

 

 

xamarin.android 使用线程池处理耗时操作时,其UI更新应该回到UI线程再更新,处理方式如下:

 

ThreadPool.QueueUserWorkItem(thread => QueryBoxThread());

 

RunOnUiThread(() => {
lvAdapter.AddData(_boxLabel.ToString());
});

 

msdn参考链接:https://docs.microsoft.com/zh-cn/xamarin/android/app-fundamentals/writing-responsive-apps

posted @ 2022-05-23 20:11  盛沧海  阅读(173)  评论(0编辑  收藏  举报