According to doc here
Called when a Preference has been changed by the user. This is called before the state of the Preference is about to be updated and before the state is persisted.
And it returns True to update the state of the Preference with the new value.
So you can do the following
editTextPreference
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
if (((newValue.toString().length() == 15) {
//
return true;
}
else{
// invalid you can show invalid message
return false;
}
})
});