title: How to set click listener to this Button
body: <p>I cant get this to work I want the sign out <code>Button</code> on this <code>preferences</code> screen to have a <code>ClickListener</code> </p>
  
  <p>This is how it looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/MI4f3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MI4f3.jpg" alt="enter image description here"></a></p>
  
  <p>Here´s the code and the <code>buttonView</code> is always NULL:</p>
  
  <pre><code>class PreferencesFragment : PreferenceFragmentCompat() {
  
      lateinit var activity: Context
  
      private var prefs: SharedPreferences = BleApplication.getInstance().getDefaultSharedPreferences()
  
      override fun onAttach(context: Context?) {
          super.onAttach(context)
          activity = requireActivity()
      }
  
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          val buttonView = view.findViewById&lt;View&gt;(R.id.btn_sign_out)
  
          if (buttonView != null) {
              buttonView.setOnClickListener {
                  Toast.makeText(getActivity(), "You clicked me.", Toast.LENGTH_SHORT).show()
              }
          }
          // Hide the divider
  /*        setDivider(ColorDrawable(Color.TRANSPARENT))
          setDividerHeight(0)*/
      }
  
      override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
          addPreferencesFromResource(R.xml.app_prefs)
      }
  }
  </code></pre>
  
  <p>I also tried the kotlinx.android.synthetic but same problem there</p>
  
  <p>Here´s the xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;PreferenceCategory
          android:layout="@layout/pref_category_text"
          android:title="@string/pref_category_remote_battery_title"&gt;
  
          &lt;SwitchPreferenceCompat
              android:key="@string/pref_key_category_remote_battery_switch"
              android:title="@string/pref_category_remote_battery_switch_title"
              android:summary="@string/pref_category_remote_battery_switch_summ"/&gt;
  
      &lt;/PreferenceCategory&gt;
  
      &lt;PreferenceCategory
          android:layout="@layout/pref_category_text"
          android:title="@string/pref_category_sign_out_title"&gt;
  
          &lt;Preference
              android:key="@string/pref_key_category_signed_out"
              android:widgetLayout="@layout/pref_category_sign_out_button"
              android:title="@string/pref_category_sign_out_button_title"
              android:summary="@string/pref_category_sign_out_buttom_summ"/&gt;
  
      &lt;/PreferenceCategory&gt;
  
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>Here is the <code>"@layout/pref_category_sign_out_button"</code> layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"&gt;
  
      &lt;Button
          android:id="@+id/btn_sign_out"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="@drawable/buttonshape"
          android:text="@string/pref_category_sign_out_title" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>