Code example for EditTextPreference

Methods: getText, setText

0
                R.string.base_directory_key); 
        final EditTextPreference baseDirectoryPreference;
        baseDirectoryPreference = (EditTextPreference) ps.findPreference(baseDirPreferenceKey);
        baseDirectoryPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String oldBaseDirectory = baseDirectoryPreference.getText();
                String newBaseDirectory = newValue.toString();
 
                if ( DEBUG ) {
                    Log.d(TAG, "onPreferenceChange(" + baseDirPreferenceKey
                            + ") -----------------------------------"); 
                    Log.d(TAG, "    - old value : " + oldBaseDirectory);
                    Log.d(TAG, "    - new value : " + newBaseDirectory);
                } 
 
                if ( oldBaseDirectory.equals(newBaseDirectory) ) {
                    if ( DEBUG ) {
                        Log.d(TAG, "    - same old value and new value");
                    } 
                    return true; 
                } 
 
                if ( !newBaseDirectory.startsWith("/mnt/sdcard/") ) {
                    String tmp = "/mnt/sdcard";
                    if ( !newBaseDirectory.startsWith("/") ) {
                        tmp += "/";
                    } 
                    tmp += newBaseDirectory;
                    newBaseDirectory = tmp;
                } 
 
                File baseDir = new File(newBaseDirectory);
                if ( !baseDir.exists() ) {
                    if ( DEBUG ) {
                        Log.d(TAG, "    - new dir was not exist and then create mkdirs.");
                    } 
                    baseDir.mkdirs();
                } 
 
                /* save new value to preference */ 
                baseDirectoryPreference.setText(newBaseDirectory);
 
                return false; 
            } 
        });