views:

86

answers:

1

How can I find my PreferenceActivity instance, which was created by a framework?

* * *

My first class.

/** This is MyAppSettings class, The instance of this class will be created by a framework **/

public class MyAppSettings extends PreferenceActivity {
    protected MySeekBarPreference mSeekBarPref;

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        addPreferencesFromResource(R.xml.prefs);

        mSeekBarPref = (MySeekBarPreference)super.findPreference("my_key");
    }
}

* * *

My second class.

public class MySeekBarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {

      // in whis code I need to get the instance of the MyAppSettings, which was
      // created by Android framework. (I paste a hypothetical func getTheInstanceOfMyAppSettings() :))
  private MyAppSettings mAppSettings = getTheInstanceOfMyAppSettings(); 

Can I find it by ID or something else?

A: 

I guess that you are looking for getPreferenceScreen()

You can use it to modify the PreferenceScreen that was defined in the xml.

For example:

private void disableHardKeyboardOptions() {
    Preference pref = getPreferenceScreen().findPreference("pref_hardkeyboard_option");
    pref.setEnabled(false);
    pref.setSummary(custom.getString(R.string.pref_no_hardkeyboard));
}
Macarse