如何在asynctask内使用FindViewById方法?
我在尝试将手机连接到蓝牙设备时要执行的异步箱要执行,如果成功连接
(我是Kotlin编程的新手)
,我想从按钮更改图标。 sstatic.net/ucglb.png“ rel =“ nofollow noreferrer”>
” https://i.sstatic.net/9ibvp.png“ rel =” nofollow noreferrer“>
如果有人能提供帮助,我会非常感谢。
I have an AsyncTask to execute while trying to connect the phone to a Bluetooth device, I want to change an icon from a button if it connects successfully
(I'm new to Kotlin programming)
I would be very grateful if anyone could help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
用第146行替换
val
Replace this with line 146
val [email protected](R.id.blue_btn)
我想提一下,从异步任务进行更改并不是真正的解决方案,因为它们旨在仅处理背景作业,因此我建议您
继续从那里发送命令来处理活动,如果您想要此事,尝试更改您传递的参数
上下文
属于活动
,例如上下文:activity
,访问 findviewbyid bycontext.findviewbyid(...)
I would like to mention, that making changes from the async task is not really a best solution, since they are designed to handle only background jobs, so I would recommend sending a command from there to handle in the Activity
Still, if you want this, try changing you passed parameter
context
to be of typeActivity
, likecontext: Activity
, and accessfindViewById
bycontext.findViewById(...)
将私有替换为内部类。
Replace private to inner class.