Using custom Preference views
I have a wallpaper in the market, want to add a setting for color preference. After days and days I can't get the color preference to work.
The test environment I am using is the standard Cube2Settings wallpaper app. I have copied across the code from https://github.com/commonsguy/cwac-colormixer which supplies a color selector as a Preference activity.
Specifically, I now have a class called "com.example.android.livecubes.cube2.ColorPreference" (and some others which it needs). In Java, the Intellisense can see this class in my Preference activity. The first lines of ColorPreference.java is:
public class ColorPreference extends DialogPreference {
My cube2settings.xml looks as follows:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/cube2_settings"
android:key="cube2wallpaper_settings">
<ListPreference
android:key="cube2_shape"
android:title="@string/cube2_settings_title"
android:summary="@string/cube2_settings_summary"
android:entries="@array/cube2_shap开发者_开发技巧enames"
android:entryValues="@array/cube2_shapeprefix" />
<com.example.android.livecubes.cube2.ColorPreference
android:key="favoriteColor"
android:defaultValue="0xFFA4C639"
android:title="Your Favorite Color"
android:summary="Blue. No yel- Auuuuuuuugh!" />
</PreferenceScreen>
Without the com.example...ColorPreference in the above xml, runs fine. With it, I get "the application process.com.example.android.livecubes has stopped unexpectantly". I don't do anything else with the ColorPrefernce at all in my code, and it compiles just fine. The xml above was copied from the example they provided, just with the class name changed.
It worries me that I can apparently type whatever I like instead of "com.example.android.livecubes.cube2.ColorPreference", and it will compile. Which makes me think this line is at fault, though of course I have tried a billion variations. Isn't there some way that you can limit/check the class name to valid classes in the Eclipse xml editor, like you can in the Java editor, or at least check it is valid without running it in the emulator? I have had this type of problem many times before.
Can anybody help with the specific problem of why the ColorPreference doesn't work, or the general one of getting class names correct in the xml?
Thanks
Peter Webb
精彩评论