Reputation: 24563
I have a PreferenceScreen with a sub PreferenceScreen:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="SOUND">
<PreferenceScreen android:title="Sound Options"
android:fragment="com.test.SoundPreferenceFragment">
</PreferenceScreen>
</PreferenceCategory>
...
The sub preference is a custom implementation of a PreferenceFragment
public class SoundPreferencesFragment extends PreferenceFragment implements
OnSharedPreferenceChangeListener {
...
I am wondering how I am supposed to start the custom fragment. In my main activity I do this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, settingsPreference).commit();
}
Which works great to start my main settings preference screen.
I then override:
@Override
public boolean onPreferenceStartFragment(PreferenceFragment fragment, Preference preference) {
getFragmentManager().beginTransaction().replace(android.R.id.content, new SoundPreferenceFragment()).commit();
return true;
}
That seems to work but I have a few questions.
EDIT:
I also tried not to extend 'onPreferenceStartFragment' in my main activity hoping that android would take care of starting the new preference correctly' It does seem to start the new PreferenceFragment but it overlays the UI right on top of the main preferences UI.
Upvotes: 0
Views: 640
Reputation: 17085
You have to create a new activity and attach the SoundPreferencesFragment . when you select the item in main setting activity , start the new activity
Upvotes: 1