The beauty of PreferenceActivity is its tight integration with Android's res/xml
. All you need to do achieve the magic of self-managed preference reading/saving, along with the UI, is define:
public class MyPreferenceActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
And define any <PreferenceScreen>
structure you need in XML file(s).
But this also seems to be its weakness: It is so tightly integrated, that I have no idea whether it is possible to use PreferenceActivity with SQLite (for a more structured preference management), without re-inventing the while (i.e. re-writing an entire "PreferenceActivity" from scratch).
For example, using OnSharedPreferenceChangeListener may provide a gateway to using PreferenceActivity with SQLite, but it still requires the res/xml
definitions to be in place - so really we are still constrained by the limitations of the res/xml method.
Is there a way to "eat the cake and have it too"? i.e. Use PreferenceActivity with SQLite in the same ease as res/xml
's.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…