can't call button id in kotlin file in android studio

52 views Asked by At

I have made a button in xml and then assigned an id but can't call the id in kotlin file because I can't import.kotlin.android......

Also I've seen videos but the gradle solution is no longer working. Please help

I've tried other solutions from youtube and stack overflow

1

There are 1 answers

2
Darshan Beladiya On
import android.widget.Button

you need to import this necessary imports

OR

Also you can use binding for call button

View Binding enabled in your module's build.gradle file.

viewBinding {
    enabled = true
}

In your activity or fragment where you want to access the views:

class YourActivity : AppCompatActivity() {
    private lateinit var binding: YourLayoutBinding // Declare view binding variable

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = YourLayoutBinding.inflate(layoutInflater)
        setContentView(binding.root)

        // Access your views via binding here
    }
    // Other methods and code
}