Gaspar Pereira
Gaspar Pereira

Reputation: 33

How can I use findViewById method inside AsyncTask?

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.

Upvotes: 1

Views: 72

Answers (3)

Dhara Jani
Dhara Jani

Reputation: 461

Replace private to inner class.

Upvotes: 0

kboskin
kboskin

Reputation: 420

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(...)

Upvotes: 1

Rahimian
Rahimian

Reputation: 102

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

Upvotes: 1

Related Questions