On 12/13/2012 11:03 PM, Jim Duda wrote:
> I want to launch a new preference screen from my main preference screen.
>
> My main preference.xml is this:
>
> <?xml version="1.0" encoding="utf-8"?>
> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
> <PreferenceScreen
> android:title="@string/pref_settings_title" >
> <CheckBoxPreference
> android:key="settingsMute"
> android:title="@string/pref_muteAudio"
> android:summary="@string/pref_muteAudio_summ"
> android:defaultValue="false" />
> <CheckBoxPreference
> android:key="settingsObjectFilter"
> android:title="@string/pref_enableObjectFilters"
> android:summary="@string/pref_enableObjectFilters_summ"
> android:defaultValue="false" />
> <CheckBoxPreference
> android:key="settingsNoStateFilter"
> android:title="@string/pref_filterObjectsNoState"
> android:summary="@string/pref_filterObjectsNoState_summ"
> android:defaultValue="false" />
> <CheckBoxPreference
> android:key="settingsEnableService"
> android:title="@string/pref_enableService"
> android:summary="@string/pref_enableService_summ"
> android:defaultValue="false" />
> </PreferenceScreen>
> <PreferenceScreen
>
> android:fragment="com.example.android.misterhouse.activity.SettingsActivity$HostsFragment"
> android:title="@string/pref_hosts_title"
> android:summary="@string/pref_hosts_title" >
> </PreferenceScreen>
> <EditTextPreference
> android:title="@string/pref_version_title"
> android:summary="@string/about_current"
> android:selectable="false" />
> </PreferenceScreen>
>
> When selecting the "pref_hosts_title", I want the
> SettingsActivity$HostsFragment to display.
> This new fragment does display, however, it doesn't replace the original
> fragment, it
> instead overlays the original fragment. The two fragments display at the
> same time.
>
> What might I be doing wrong?
When I select the android:fragment, I've found out that what happens is an
entire new
SettingActivity is started. I was only expecting a new HostsFragment to be
created.
I'm obviously missing something fundamental about the PresenceFragment life
cycle.
I'm reading the docs, but I just don't see my misunderstanding.
Thanks for any help you can offer,
Jim
>
> The activity which uses these XML are as follows:
>
> public class SettingsActivity extends PreferenceActivity {
>
>
> public static class SettingsFragment extends PreferenceFragment {
>
> public static final String TAG = "SettingsFragment";
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> Log.v(TAG,"onCreate");
> super.onCreate(savedInstanceState);
>
> // Load the preferences from an XML resource
> addPreferencesFromResource(R.xml.preferences);
> getPreferenceManager(
> ).setSharedPreferencesMode(MODE_MULTI_PROCESS);
> }
>
> }
>
> public static class HostsFragment extends PreferenceFragment {
>
> public static final String TAG = "HostsFragment";
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> Log.v(TAG,"onCreate");
> super.onCreate(savedInstanceState);
>
> // Load the preferences from an XML resource
> addPreferencesFromResource(R.xml.hosts);
> }
>
>
> }
>
>
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> Log.v(TAG,"onCreate");
> super.onCreate(savedInstanceState);
>
> // Load the preferences from an XML resource
> //addPreferencesFromResource(R.xml.preferences);
>
> // Display the fragment as the main content.
> if (android.os.Build.VERSION.SDK_INT >= 11) {
> Log.v(TAG,"Building SettingsFragment");
> getFragmentManager().beginTransaction()
> .replace(android.R.id.content, new SettingsFragment())
> .commit();
> }
> }
>
> }
>
> Any advice appreciated.
>
> Regards,
>
> Jim
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en