I have an XML file called user_preferences that contains my
preferences for my application.

How do I get hold of the different preference Views so that I can
validate them?

Currently I have the code below which is not working because
getSharedPreferences does not return a View.



        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                addPreferencesFromResource(R.xml.user_preferences);

                //get a handle on preferences that require validation
                timeLimitPreference = (EditTextPreference) 
this.getSharedPreferences
("time_limit", MODE_PRIVATE);
                timeLimitPreference.setOnPreferenceChangeListener(new
OnPreferenceChangeListener() {

                        @Override
                        public boolean onPreferenceChange(Preference 
preference, Object
newValue) {
                                //Check that the string is an integer.

                                if( newValue.toString()!=null && 
newValue.toString().matches("\\d
{1-5}") ) {
                                        Log.e(TAG, "Not a number");
                                        newValue = 30;
                                        return true;
                                }
                                Log.e(TAG, "Is a number");
                                return false;
                        }
                });

        }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to