Using xml Syntax Highlighting
- android:input_type="numberDecimal|numberSigned"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
of the EditText element, one can use the following:
Using java Syntax Highlighting
- EditTextPreference myEditTextPreference = (EditTextPreference) findPreference("myPrefKey");
- myEditTextPreference
- .setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference,
- Object newValue) {
- try {
- String input = newValue.toString();
- if (containsOnlyNumbers(input)) {
- int result = Integer.parseInt(input);
- if (result < 0) {
- result = 0;
- }
- // Parsing was successful. Use the result..
- // TODO
- } else {
- Log.e(TAG, "Invalid value input '" + input
- + "', using old one");
- return false;
- }
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
- });
- private boolean containsOnlyNumbers(String s) {
- if(s.length()<1) {
- return false;
- }
- for (int i = 0; i < s.length(); i++) {
- if (!Character.isDigit(s.charAt(i))) {
- return false;
- }
- }
- return true;
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4



