I am trying to establish a settings screen for my Android 4.0+ app. I can not get the two checkboxes vibratePreference and soundPreference to display. I don’t think UserPreferencesFragment ever instantiates. Below are the files involved. I’ve been on this for a couple of nights and I can not figure out what I’m missing. What am I over looking?
Thanks, PLA
preferences_headers.xml
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >
<header
android:fragment="com.hometelco.hfa.activities.UserPreferencesFragment"
android:summary="Home Field Advantage user settings"
android:title="User Settings" />
</preference-headers>
preferences.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="User Settings" >
<CheckBoxPreference
android:defaultValue="true"
android:key="vibratePreference"
android:summary="Vibrate on adds and updates"
android:title="Vibrate" />
<CheckBoxPreference
android:defaultValue="true"
android:key="soundPreference"
android:summary="Play sound on adds and updates"
android:title="Sound" />
</PreferenceCategory>
</PreferenceScreen>
UserPreferencesActivity.java
package com.hometelco.hfa.activities;
import java.util.List;
import android.preference.PreferenceActivity;
import android.util.Log;
import com.hometelco.hfa.R;
public class UserPreferencesActivity extends PreferenceActivity {
private static final String TAG = "UserPreferencesActivity";
public void onBuildHeaders(List<Header> target) {
Log.i(TAG, "onBuildHeaders before load");
loadHeadersFromResource(R.xml.preference_headers, target);
Log.i(TAG, "onBuildHeaders after load");
}
}
UserPreferencesFragment.java
package com.hometelco.hfa.activities;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.util.Log;
import com.hometelco.hfa.R;
public class UserPreferencesFragment extends PreferenceFragment {
private final static String TAG = "UserPreferencesFragment";
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "UserPreferencesFragment onCreate");
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
I apologize. My code was actually working the entire time. I was just not pressing on the settings header. When I did my check-boxes appeared. This is not what I want so I changed
PreferenceActivityto the code seen below.Thanks to everyone who helped me find the error of my ways.
PLA