title: How do I get an button Onclicklistener in class for Android?
body: <p>I am developing <code>Baidu notification</code> in Android. The <code>Baidu notification</code> has no <code>Button</code>. So I decide to create custom <code>Baidu notification</code> and add the <code>Button</code> on it. </p>
  
  <p>I pass an id to a <code>Class</code> and set it to the <code>Button</code>. I want to implement <code>OnCLickListener</code> and get click event in a <code>Class</code>.</p>
  
  <p>In <strong><code>Activity</code></strong> , I use the following code to pass the id of <code>button</code> to <strong><code>customNoti</code></strong> class.</p>
  
  <pre><code>private fun initMyCustomNotiBuilder() {
          val customNoti = CustomNoti(
              R.layout.notification_custom_builder,
              R.id.notification_icon,
              R.id.notification_title,
              R.id.notification_text,
              R.id.btn_OK,this
          )
      }
  </code></pre>
  
  <p>The code is like the following</p>
  
  <pre><code>class CustomNoti : CustomPushNotificationBuilder, View.OnClickListener{
  
      lateinit var btn:Button
      lateinit var context:Context
  
      companion object{
          const val TAG = "CustomNoti"
      }
  
      constructor(layoutId: Int, layoutIconId: Int, layoutTitleId: Int, layoutTextId: Int, buttonID: Int,context: Context) : super(layoutId, layoutIconId, layoutTitleId, layoutTextId){
          this.context = context
          btn = Button(context)
          btn.id = buttonID
          btn.setOnClickListener(this)
      }
  
      override fun onClick(view: View?) {
          Log.d(TAG,"onClick view:${view?.id}")
      }
  }
  </code></pre>
  
  <p>The <code>Baidu notification</code> has button now , but the <code>clicklistener</code> is not working when I click the button.</p>
  
  <p>How do I get an <code>Onclicklistener</code> in class ?</p>
  
  <p>Did I missing something ?</p>