Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created Dec 10, 2017
Embed
What would you like to do?
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Toast error = Toast.makeText(getContext(), R.string.plan_length_error_message, Toast.LENGTH_SHORT);
String planKey = getString(R.string.plan_length_key);
if (preference.getKey().equals(planKey)) {
String stringSize = ((String) (newValue)).trim();
if (stringSize.equals("")) stringSize = getString(R.string.plan_length_default_value);
try {
int size = Integer.parseInt(stringSize);
if (size < 1 || size > 30) {
error.show();
return false;
}
} catch (NumberFormatException nfe) {
error.show();
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment