I’m extending ListPreference to add functionality to change the preference’s summary when it’s selected entry changes. So far I’ve only extended the class, provided constructors, and set a few options. When I run the activity that references this class in XML, the app crashes with an InflateException:
E/AndroidRuntime( 1542): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.grooveshark.android.radio/com.grooveshark.android.radio.activity.SettingsActivity}: android.view.InflateException: Binary XML file line #88: Error inflating class HighQualityPreference
E/AndroidRuntime( 1542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
E/AndroidRuntime( 1542): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
E/AndroidRuntime( 1542): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime( 1542): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
E/AndroidRuntime( 1542): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1542): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 1542): at android.app.ActivityThread.main(ActivityThread.java:3835)
E/AndroidRuntime( 1542): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1542): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 1542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
E/AndroidRuntime( 1542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
E/AndroidRuntime( 1542): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 1542): Caused by: android.view.InflateException: Binary XML file line #88: Error inflating class HighQualityPreference
Here’s the Java:
public class HighQualityPreference extends ListPreference
{
public HighQualityPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
setEntries(R.array.high_quality_options);
setEntryValues(R.array.high_quality_option_values);
setSummary("Six squirrels while on a WiFi connection");
}
public HighQualityPreference(Context context)
{
super(context);
}
}
Here’s the XML:
<HighQualityPreference android:key="@string/prefs_high_quality_option"
android:persistent="true" />
As you can see, all I’ve done is extend the class. To add functionality to ListPreference, do I need to do more than extend it? Meaning, do I need to override any other functions or call through to other functions? Do I need to set the XML content view? I do want to use the original XML, I just want to update the summary when the chosen entity changes.
Try adding the fully-qualified package for the component, i.e.