Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value doesn't work #28

Open
kraxarn opened this issue Jul 4, 2017 · 4 comments
Open

Default value doesn't work #28

kraxarn opened this issue Jul 4, 2017 · 4 comments

Comments

@kraxarn
Copy link

kraxarn commented Jul 4, 2017

When setting a defaultValue in the xml file for the settings, it doesn't show or set it until the dialog is opened. There, the default color is shown.

No color shown instead of the set one

But when you open it

@denisk20
Copy link
Collaborator

denisk20 commented Jul 5, 2017

Can you post your code which sets the default value?

@kraxarn
Copy link
Author

kraxarn commented Jul 5, 2017

In my preference xml file I have

<PreferenceCategory android:title="Colors">
    <yuku.ambilwarna.widget.AmbilWarnaPreference
        android:key="color_yellow"
        android:defaultValue="0xffff00"
        android:title="Yellow" />
</PreferenceCategory>

Which I then load in a PreferenceFragment in an onCreate method.

@denisk20
Copy link
Collaborator

denisk20 commented Jul 5, 2017

I'll take a look, hopefully soon. Let me know if you come up with a pull request, it will be highly appreciated.

@kraxarn
Copy link
Author

kraxarn commented Jul 5, 2017

So I tried playing around with this a little bit more and found a "workaround" for it.
Within my preferences fragment, I tried doing
((AmbilWarnaPreference) getPreferenceScreen().findPreference("color_yellow")).forceSetValue(0xffff00);
This, as I thought, didn't work and it just set that checkerboard. However, if I instead try
((AmbilWarnaPreference) getPreferenceScreen().findPreference("color_yellow")).forceSetValue(Color.YELLOW);
It sets the color just fine.

Found a "fix", if I instead set defaultValue to -256 (which is the value of Color.YELLOW), it sets the default value just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants