【Android】错误信息 Only the original thread that created a view hierarchy can touch its views
来源:互联网 发布:上海丝绸哪里买好 知乎 编辑:程序博客网 时间:2024/05/18 00:32
今天碰到一个问题,自定义dialog,点击其中的按钮,dialog消失,同时界面中的某个view显示出来,会出现标题中的错误信息。下面贴上错误代码
PromptDialog dialog = new PromptDialog(context); dialog.setOnDismissListener(new PromptDialog.OnDismissListener() { @Override public void onDismiss() { dialog.dismiss(); // 引起崩溃的代码就是这行,因为这里不是主线程,而所有更新UI的操作都需要在主线程完成 // 所以需要在这里通知主线程,让它做更新操作 moveView.setVisibility(View.VISIBLE); } });
所以将代码改成如下就行了:
PromptDialog dialog = new PromptDialog(context); dialog.setOnDismissListener(new PromptDialog.OnDismissListener() { @Override public void onDismiss() { dialog.dismiss(); // 将操作给主线程 context.runOnUiThread(rb); } });Runnable rb = new Runnable() { @Override public void run() { // 更新UI moveView.setVisibility(View.VISIBLE); } };
阅读全文
0 0
- 【Android】错误信息 Only the original thread that created a view hierarchy can touch its views
- Android Only the original thread that created a view hierarchy can touch its views.
- Android单元测试 Only the original thread that created a view hierarchy can touch its views.
- android:Only the original thread that created a view hierarchy can touch its views
- Android 解决Only the original thread that created a view hierarchy can touch its views异常
- Only the original thread that created a view hierarchy can touch its views的相关
- 报Only the original thread that created a view hierarchy can touch its views错误解决
- Only the original thread that created a view hierarchy can touch its views错误
- 报Only the original thread that created a view hierarchy can touch its views错误解决
- 报Only the original thread that created a view hierarchy can touch its views错误解决
- Only the original thread that created a view hierarchy can touch its views错误相关
- Only the original thread that created a view hierarchy can touch its views的相关
- Only the original thread that created a view hierarchy can touch its views
- 关于Only the original thread that created a view hierarchy can touch its views的解决方案
- Only the original thread that created a view hierarchy can touch its views.
- 解决Only the original thread that created a view hierarchy can touch its views
- Only the original thread that created a view hierarchy can touch its views
- 关于Only the original thread that created a view hierarchy can touch its views的解决方案
- 【上学反而学会坏习惯?家长可以这…
- 【教育:从清洁工作中看见孩子的改…
- 2017中国广州国际工业自动化技术及装备展览会会刊(参展商名录)
- 【伦敦大学教我的5个逆转心理学】…
- 【爱上你,是我此生最幸福的决定】…
- 【Android】错误信息 Only the original thread that created a view hierarchy can touch its views
- 【爱情大停电?赶快按下这二个钮抢…
- 【爱一个人,就像吃无菜单料理套餐…
- 吴京、赵薇都被吸引来了~~1亿人次参与的奇迹,就差你了!
- 【CUGBACM15级BC第27场 A】hdu 5162 Jump and Jump...
- centos7开放及查看端口
- 【幼儿教育不是精英教育】据报道,…
- 最大子串和(动态规划)(简洁写法)
- 【你为什么总想著与猪比美】「川叔…