Title: Better handling of float/integer in preferences · Issue #503 · androidannotations/androidannotations · GitHub
Open Graph Title: Better handling of float/integer in preferences · Issue #503 · androidannotations/androidannotations
X Title: Better handling of float/integer in preferences · Issue #503 · androidannotations/androidannotations
Description: Hello, I'm using the @PREF annotations along with PreferenceFragment so that the built-in preference UI can publish my AA generated preferences. It works great with string/checkbox pref (edited with : EditTextPreference / CheckBoxPrefere...
Open Graph Description: Hello, I'm using the @PREF annotations along with PreferenceFragment so that the built-in preference UI can publish my AA generated preferences. It works great with string/checkbox pref (edited wit...
X Description: Hello, I'm using the @PREF annotations along with PreferenceFragment so that the built-in preference UI can publish my AA generated preferences. It works great with string/checkbox pref (edited...
Opengraph URL: https://github.com/androidannotations/androidannotations/issues/503
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Better handling of float/integer in preferences","articleBody":"Hello, \n\nI'm using the @Pref annotations along with PreferenceFragment so that the built-in preference UI can publish my AA generated preferences.\n\nIt works great with string/checkbox pref (edited with : `EditTextPreference` / `CheckBoxPreference`), but there is an issue with a number (int or float).\n\nI use a this declaration to publish my float preference :\n\n```\n \u003cEditTextPreference\n android:key=\"listMaxSpeed\"\n android:numeric=\"integer\"\n android:title=\"Max speed for list\" /\u003e\n```\n\nWhen I update the value and try to use it with the `Pref_` class, I get this error : \n\n```\n Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Float\n at android.app.SharedPreferencesImpl.getFloat(SharedPreferencesImpl.java:254)\n at com.googlecode.androidannotations.api.sharedpreferences.FloatPrefField.getOr(FloatPrefField.java:34)\n```\n\nThe reason is `EditTextPreference` convert the value to string which is not very smart.\nOf course, the `Pref_` class expects a float (and rightfully so).\n\nWould it possible to add this use case when doing : \n\n```\n public float getOr(float defaultValue) {\n return sharedPreferences.getFloat(key, defaultValue);\n }\n```\n\n... and add a conversion from string to float if the value has been converted to a string by the (stupid) preference UI ?\n\nNote : I can provide a patch (and tests).\n","author":{"url":"https://github.com/PerfectCarl","@type":"Person","name":"PerfectCarl"},"datePublished":"2013-02-13T15:23:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/503/androidannotations/issues/503"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:98518fa2-1ddf-59ab-a7da-51f5eae7740f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E12A:275199:45C901:5D77C4:6A611CE3 |
| html-safe-nonce | a34fb8287e618883884386218885644f3a341778c26e04e497e3a9a4e05f0841 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTJBOjI3NTE5OTo0NUM5MDE6NUQ3N0M0OjZBNjExQ0UzIiwidmlzaXRvcl9pZCI6IjUzNTgzMTYxODk5ODY2NTk1NTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fbd39a8698a12d154459aba434d82dd2d1d7e83f079e2dfb7b76fe3dfcc00ec5 |
| hovercard-subject-tag | issue:10957680 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/androidannotations/androidannotations/503/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dbf9cb200dc33bbe7bf700d6a040c50ecef349a1f0285f060672732374650d94/androidannotations/androidannotations/issues/503 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dbf9cb200dc33bbe7bf700d6a040c50ecef349a1f0285f060672732374650d94/androidannotations/androidannotations/issues/503 |
| og:image:alt | Hello, I'm using the @PREF annotations along with PreferenceFragment so that the built-in preference UI can publish my AA generated preferences. It works great with string/checkbox pref (edited wit... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | PerfectCarl |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5d23cf1c0cd2fa53870b9a743b3e1bc3ff0d0b0b3a477b50251e1c9dd8ecb93d |
| turbo-cache-control | no-preview |
| go-import | github.com/androidannotations/androidannotations git https://github.com/androidannotations/androidannotations.git |
| octolytics-dimension-user_id | 1315313 |
| octolytics-dimension-user_login | androidannotations |
| octolytics-dimension-repository_id | 3116751 |
| octolytics-dimension-repository_nwo | androidannotations/androidannotations |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3116751 |
| octolytics-dimension-repository_network_root_nwo | androidannotations/androidannotations |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | abf5a2f79ab9b533c5865f5281057f7d17cf18f3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width