What's Your Preference?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
We also need to update AndroidManifest.xml to reference this activity, so we
can launch it later:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apt.tutorial"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name">
<activity android:name=".LunchList"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailForm">
</activity>
<activity android:name=".EditPreferences">
</activity>
</application>
</manifest>
Step #3: Connect the Preference Activity to the Option Menu......
Menu
Now, we can add a menu option to launch the EditPreferences activity.
We need to add another
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/add"
android:title="Add"
android:icon="@drawable/ic_menu_add"
/>
<item android:id="@+id/prefs"
android:title="Settings"
android:icon="@drawable/ic_menu_preferences"