1
如何查找由框架創建的PreferenceActivity實例?Android PreferenceActivity實例
* * *
我的第一課。
/** 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");
}
}
* * *
我的第二類。
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();
我可以通過ID或其他東西找到它嗎?
哪裏,怎麼樣?在你的語境中可能是「this」。請編輯您的原始問題,併發布您創建的詳細代碼以及您想要查找實例的位置。 – Pentium10 2010-07-11 13:49:34