skip to Main Content

When I implemented the member in the class for the on click listener as shown below:

class QuizQuestionsActivity : AppCompatActivity(), View.OnClickListener {

I was given the option of implementing it as:

 override fun onClick(p0: View?) {

I need it to be

override fun onClick(v: View?) {

can someone explain the difference and why I am not getting the option of v: View

2

Answers


  1. Both of those functions are the same, it’s just a different name for the View variable. Kotlin parameters are listed with the parameter name first, then the class name.

    If you want p0 to be v instead, just change the parameter name to be v.

    Login or Signup to reply.
  2. Kotlin provide default parameter with alphabets and digits you can simply change it with your variable name like —

    override fun onClick(v: View?) { }
    
    override fun onClick(view: View?) { } 
    
    override fun onClick(myView: View?) { } 
    

    It’s quit good and it’s meaningful variable name that remember as long time. where P0 and P1 named variable is not like good to remember.

    Hope You can understand what I mean to say.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search