I have this custom SpannableStringBuilder
class:
public class ExpressionBuilder extends SpannableStringBuilder{
public ExpressionBuilder(CharSequence text){
super(text);
}
@Override
public SpannableStringBuilder replace(int start, int end, CharSequence tb, int tbstart,
int tbend) {
// do something...
}
}
And an Editable.Factory
needed to converts a TextView
into an Editable
required by the SpannableStringBuilder
:
private final Editable.Factory editableFactory = new Editable.Factory() {
@Override
public Editable newEditable(CharSequence source) {
return new ExpressionBuilder(source);
}
};
Then attach the TextView
to the Editable.Factory
:
myTextView.setEditableFactory(editableFactory);
What the above code does basically, is whenever a new string is appended to the TextView
, the replace()
method is called in the ExpressionBuilder
and all its parameters are set. I don't understand how the append()
method of the TextView
calls the replace()
method of the SpannableStringBuilder
and how its parameters are set. I searched the documentation but I didn't find any explanation.
Any help, please. Thanks.