title: Preference Activity on Preference Click Listener
body: <p>I am building a Preference Activity where most of the preferences in the list will be executing code and not modifying a SharedPreference directly. My preferences.xml file looks like this.</p>
  
  <p>
  </p>
  
  <pre><code>&lt;PreferenceCategory
      android:title="Connection" &gt;
  
      &lt;Preference
          android:id="@+id/settings_connectToNewComputer"
          android:key="connectToNewComputer"
          android:summary="Currently connected to:"
          android:title="Connect to new computer" /&gt;
  
      &lt;Preference
          android:id="@+id/removeDevice"
          android:key="removeDevice"
          android:summary="Remove this device from the computer's whitelist"
          android:title="Remove this device from computer" /&gt;
  
  &lt;/PreferenceCategory&gt;
  
  &lt;PreferenceCategory
      android:title="About" &gt;
  
      &lt;Preference
          android:id="@+id/settings_About"
          android:key="about"
          android:summary="About me and my thanks to those who made this app great"
          android:title="About Hue Pro" /&gt;
  
      &lt;Preference
          android:id="@+id/contact"
          android:key="contact"
          android:summary="Contact me with comments, bugs, and suggestions for updates"
          android:title="Contact me" /&gt;
  
  &lt;/PreferenceCategory&gt;
  </code></pre>
  
  <p></p>
  
  <p>My goal is to have a block of code executed when a one of these preferences are clicked. Similar to the "Clear search history" in the Google Play settings preference menu. (<a href="http://i.imgur.com/qnHbJX9.png">http://i.imgur.com/qnHbJX9.png</a>) </p>
  
  <p>Does anyone know how to make this possible?</p>
  
  <p>I have to add that I have tried using findPreference("KeyNameHere") but it always returns null.</p>
  
  <p>Thank you!</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>I added in this code and implemented OnPreferenceClickListener:</p>
  
  <pre><code>@Override
  public boolean onPreferenceClick(Preference preference) {
      return false;
  }
  </code></pre>
  
  <p>But this method never gets called. Is there another way to do this?</p>
  
  <hr>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>I have found that if I take out the PreferenceCategory tags so I am left with this: </p>
  
  <pre><code>&lt;Preference
      android:id="@+id/settings_connectToNewComputer"
      android:key="connectToNewComputer"
      android:summary="Currently connected to:"
      android:title="Connect to new computer" /&gt;
  
  &lt;Preference
      android:id="@+id/removeDevice"
      android:key="removeDevice"
      android:summary="Remove this device from the computer's whitelist"
      android:title="Remove this device from computer" /&gt;
  
  &lt;Preference
      android:id="@+id/settings_About"
      android:key="about"
      android:summary="About me and my thanks to those who made this app great"
      android:title="About Hue Pro" /&gt;
  
  &lt;Preference
      android:id="@+id/contact"
      android:key="contact"
      android:summary="Contact me with comments, bugs, and suggestions for updates"
      android:title="Contact me" /&gt;
  </code></pre>
  
  <p>and call this:</p>
  
  <pre><code>getPreferenceScreen().setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
  
          @Override
          public boolean onPreferenceClick(Preference preference) {
              return false;
          }
      });
  </code></pre>
  
  <p>then I actually get a response from the click event. The only down side is I have to remove the preference grouping. Anyone know why this is and any way to fix it?</p>