title: How to set a non-inline OnClickListener in Kotlin?
body: <p>I want to attach a <code>View.OnClickListener</code> to a <code>Button</code>.  I don't want the <code>OnClickListener</code> to be an inline anonymous function definition.  Rather, I want to define it outside the bounds of the <code>onCreateView()</code> function.</p>
  
  <p>In Java, I would do this as follows:</p>
  
  <pre><code>@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                         Bundle savedInstanceState)
  {
      View view = inflater.inflate(R.layout.my_layout, container, false);
      View my_btn = view.findViewById(R.id.my_btn);
      my_btn.setOnClickListener(handleButtonClick);
      return view;
  }
  
  View.OnClickListener handleButtonClick = new View.OnClickListener()
  {
      @Override public void onClick(View v) 
      {
          Log.d("my_tag", "click!")
      }
  }
  </code></pre>
  
  <p>Other answers seems to suggest the following will work, but it does not compile for me:</p>
  
  <pre><code>    override fun onCreateView(name: String?, context: Context?, attrs: AttributeSet?): View
      {
          var view = super.onCreateView(name, context, attrs)
          my_btn.setOnClickListener( handleButtonClick  )
          return view
      }
  
      private val handleButtonClick = View.OnClickListener 
      {  
          view-&gt;
          Log.d("my_tag", "click!")
      }
  </code></pre>
  
  <p>What is wrong with the above, and how can I define an <code>OnClickListener</code> as a named property on my <code>Activity</code> class?</p>