title: Android: how do I call findPreference() from my main activity?
body: <p>I'm handling the preferences screen for my Android app. I want to disable (grey it out) an item if the preceding one has a specific value.</p>
  
  <p>I have implemented two classes: MainActivity and PreferencesActivity.</p>
  
  <p>In MainActivity I do:</p>
  
  <pre><code>public class MainActivity extends Activity implements OnSharedPreferenceChangeListener {
  ...
      public void onCreate (Bundle savedInstanceState) {
          ...
          sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
          sharedPrefs.registerOnSharedPreferenceChangeListener(this);
          ...
      }
  </code></pre>
  
  <p>Then, when my preferences are requested by the user:</p>
  
  <pre><code>startActivity(new Intent(this, PreferencesActivity.class));
  </code></pre>
  
  <p>Then, to handle preferences in MainActivity, I do:</p>
  
  <pre><code>@Override
  public void onSharedPreferenceChanged (SharedPreferences prefs, String key) {
      if ("sport".equals(key)) {
          sport = prefs.getString("sport", "");
          ListPreference lp = findPreference("match_duration");
          if (sport.equals(getString(R.string."sport_soccer"))) {
              lp.setEnabled(false);
          }
      }
      ...
   }
  </code></pre>
  
  <p>The problem is I can't call findPreference in MainActivity ("The method findPreference(String) is undefined for the type MainActivity"...).
  Is my approach wrong? Shoud I implement onSharedPreferenceChanged() method in PreferencesActivity? If so, how do I use MainActivity properties in PreferencesActivity?</p>