要重写 Android 的 onTextChanged 方法而不改变其行为,可以按照以下步骤进行操作:
public class CustomEditText extends EditText {
public CustomEditText(Context context) {
super(context);
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
// 添加你想要执行的逻辑代码,或者直接调用父类的方法保留默认行为
super.onTextChanged(text, start, lengthBefore, lengthAfter);
}
}
通过这种方式,你可以在自定义的 onTextChanged 方法中执行你想要的逻辑代码,或者调用父类的方法保留默认行为。