-
Notifications
You must be signed in to change notification settings - Fork 12
House your settings or preferences in PreferenceFragment
rutura edited this page Apr 16, 2017
·
1 revision
- Have a Fragment extend PreferenceFragment and call the addPreferencesFromResource method:
public class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Load preference data from XML
addPreferencesFromResource(R.xml.settings);
}
}
- Load the fragment when necessary:
@Override
public void onClick(View v) {
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(android.R.id.content, new SettingsFragment());
ft.addToBackStack(null);
ft.commit();
}
-
Ofcourse make sure the settings.xml file is hosted at /res/xml/settings.xml
-
Relevant files:
-
Direct link to app: