如何在asynctask内使用FindViewById方法?

发布于 2025-02-11 13:35:27 字数 297 浏览 1 评论 0原文

我在尝试将手机连接到蓝牙设备时要执行的异步箱要执行,如果成功连接

(我是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)

Main Code

enter image description here

I would be very grateful if anyone could help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最美的太阳 2025-02-18 13:35:27

用第146行替换
val

Replace this with line 146
val [email protected](R.id.blue_btn)

一杆小烟枪 2025-02-18 13:35:27

我想提一下,从异步任务进行更改并不是真正的解决方案,因为它们旨在仅处理背景作业,因此我建议您

继续从那里发送命令来处理活动,如果您想要此事,尝试更改您传递的参数上下文属于活动,例如上下文:activity,访问 findviewbyid by context.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 type Activity, like context: Activity, and access findViewById by context.findViewById(...)

旧竹 2025-02-18 13:35:27

私有替换为内部类。

Replace private to inner class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文