I know this might be a duplicate from: What to use instead of "addPreferencesFromResource" in a PreferenceActivity?
But I still can not get the code to work and would appreciate some help. I can not get the: "addPreferencesFromResource(R.xml.preferences);" to work.
preferences is not resolved, even though it is in the R.xml folder.
I followed the example in the above link to the letter.
Please help!!
package com.example.oasisreference;
import android.R;
import android.R.xml;
//import android.annotation.TargetApi;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
public class Prefs extends PreferenceActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}
preferences.xml in the Res.xml folder
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android" >
<EditTextPreference
android:title="User Name"
android:key="name"
android:summary="Enter your name"
></EditTextPreference>
<CheckBoxPreference
android:title="Euro Currency"
android:defaultValue="false"
android:key="euro"
android:summary="Check for Use Cost Calculator to be in Euros/Liters">
</CheckBoxPreference>
</PreferenceScreen>
menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/aboutUs"
android:title="About the Author">
</item>
<item
android:id="@+id/preferences"
android:title="Preferences">
</item>
<item
android:id="@+id/exit"
android:title="Exit">
</item>
</menu>