Home > Software engineering >  How can I use findViewById method inside AsyncTask?
How can I use findViewById method inside AsyncTask?

Time:06-29

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.

CodePudding user response:

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

CodePudding user response:

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

  • Related