/**
* This filter will constrain edits not to make the length of the text
* greater than the specified length.
*/
public class LengthSubjectFilter implements InputFilter {
public LengthSubjectFilter(int max) {
mMax = max;
}
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
int keep = mMax - (dest.length() - (dend - dstart));
checkSubject(mSubjectTextEditor.getText().toString());
if (keep <= 0) {
return "";
} else if (keep >= end - start) {
return null; // keep original
} else {
return source.subSequence(start, start + keep);
}
}
private int mMax;
* This filter will constrain edits not to make the length of the text
* greater than the specified length.
*/
public class LengthSubjectFilter implements InputFilter {
public LengthSubjectFilter(int max) {
mMax = max;
}
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
int keep = mMax - (dest.length() - (dend - dstart));
checkSubject(mSubjectTextEditor.getText().toString());
if (keep <= 0) {
return "";
} else if (keep >= end - start) {
return null; // keep original
} else {
return source.subSequence(start, start + keep);
}
}
private int mMax;
}
mSubjectTextEditor.setFilters(new InputFilter[]{ new LengthSubjectFilter(40) });