title: Kotlin - how to make an onClick function referrable through a fragment?
body: <p>I'm trying to implement a simple rating bar (<code>rb</code>) in Android Studio using Kotlin. To test out the rating bar (X stars out of 5), I'm using the Toast function to display the designated rating value upon clicking the "Apply" button (<code>button</code>). I'm currently working in a fragment, which I believe is the source of my issue. All of this code is within the fragment's <code>override fun onCreateView(...)): View? {</code> section. </p>
  
  <pre><code>    btn = root.findViewById&lt;View&gt;(R.id.button) as Button
      rb = root.findViewById&lt;View&gt;(R.id.rb) as RatingBar
  
      fun click(view: View) {
          val ratingvalue = rb.rating
          Toast.makeText(context!!, "Rating is: " + ratingvalue, Toast.LENGTH_LONG).show()
      }
  </code></pre>
  
  <p>The function name <code>click</code> is grayed-out, stating that it is never called. To clarify, I have designated this to be the button's onClick function name, as so: <code>android:onClick="click"</code>. When clicking the button, no text shows up and the app crashes.</p>
  
  <p>Any insight to this issue would be greatly appreciated.</p>