I'm getting a Error inflating class DropDownPreference when trying to create a settings screen in my app. I've added a button to my action bar that I want to launch the settings activity which contains a settings fragment, set up like this.
So I have my SettingsActivity:
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
}
And the XML in question:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/pref_title"
android:layout_height="match_parent"
android:layout_width="match_parent">
<PreferenceCategory
android:key="pref_video"
android:title="@string/pref_video_title">
<DropDownPreference
android:key="pref_video_quality"
android:title="@string/pref_video_quality"
android:summary="@string/pref_summary_video_quality"
android:entries="@array/pref_entries_video_quality"
android:entryValues="@array/pref_entries_video_quality" />
</PreferenceCategory>
</PreferenceScreen>
I know from searching around that this error generally points to something wrong elsewhere in the code, but I'm really not sure where my error could be. This is the code in my MainActivity that is supposed to launch the SettingsActivity:
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case R.id.preferences:
// Code to show SettingsActivity
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
break;
default:
break;
}
return true;
}
Thanks for any help