Home > Software design >  setOnClickListener is not showing in intellij
setOnClickListener is not showing in intellij

Time:01-25

setOnClickListener is not showing in intellij even the textview names i can't write them without R.id.the_name

enter image description here

CodePudding user response:

This is not how android works. It seems you miss the very basics.

R.id.button is just an Int, the id of a view. To get the view you can do findViewById(id) for example.

So then in your case maybe:

val button: Button = findViewById(R.id.button)
button.setOnClickListener {
    //on click
}

CodePudding user response:

You should implement view binding to your projects.

https://developer.android.com/topic/libraries/view-binding

So instead of val btn = findViewById<Button>(R.id.yourbuttonId) you can val btn = binding.yourbuttonId

  •  Tags:  
  • Related