sharedpreferences - How can I enforce an exact string length in Android preferences? -


i have preference screen that, when setting enabled, has several strings must particular length (# of characters). of strings required. ideally when user has enabled setting should not able apply changes until strings filed in appropriate length. note i'm not talking max length, exact character count.

how can enforce rules on user? there way through built-in preference controls or have build custom fragment?

the preference class has onpreferencechange listener. public abstract boolean onpreferencechange (preference preference, object newvalue);

by returning false listener, new value not accepted:

public boolean onpreferencechange(preference pref, object newvalue) {   if (pref == mystringpreferencetovalidate) {       final string newvaluestr = (string) newvalue;       if (newvaluestr.length() != xx) {         // don't save it, not correct length         return false;       }       return true;    } } 

check out full documentation here: http://developer.android.com/reference/android/preference/preference.onpreferencechangelistener.html


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -