-
Notifications
You must be signed in to change notification settings - Fork 2
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
Crash When Using EditTextPreference with Numerical Default #4
Comments
Interesting! I haven't used EditTextPreference personally, so this is an
|
From @denley on October 1, 2015 7:53 In case anyone else runs into this issue, I've been able to work around it by subclassing public class IntegerEditTextPreference extends EditTextPreference {
public IntegerEditTextPreference(final Context context) {
super(context);
}
public IntegerEditTextPreference(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public IntegerEditTextPreference(final Context context, final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public IntegerEditTextPreference(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override protected String getPersistedString(final String defaultReturnValue) {
int defaultAsInt;
try {
defaultAsInt = Integer.parseInt(defaultReturnValue);
} catch (NumberFormatException e) {
// No default is set
defaultAsInt = 0;
}
final int intValue = getPersistedInt(defaultAsInt);
return Integer.toString(intValue);
}
@Override protected boolean persistString(final String value) {
try {
return persistInt(Integer.parseInt(value));
}catch(NumberFormatException e) {
// This shouldn't happen as long as it has inputType="number"
return false;
}
}
} |
Sorry I've been really busy the past few months. Pull requests are totally On Tue, Dec 1, 2015, 10:02 AM David Ferrand notifications@github.com
|
From @denley on September 30, 2015 11:41
When using a numerical value as the
defaultValue
attribute in anEditTextPreference
, PSync seems to determine that the preference value associated with the key should be anint
rather than aString
(as it would be if thedefaultValue
attribute was omitted).The problem is that
EditTextPreference
saves the value into theSharedPreferences
file as aString
, so it causes a crash when trying to read the value using PSync.The following example will cause the crash:
I think the most ideal solution here would be to detect the desired type from the
inputType
xml attribute and have PSync load the String value and parse it to the appropriate type. Though that may be difficult to get right in every case. If that proves unfeasible, PSync should just use a String type forEditTextPreference
values.Copied from original issue: Flipboard#5
The text was updated successfully, but these errors were encountered: