0

I'd like to override two methods of TextView (of which AppCompatEditText is a subclass) with the following signatures:

 protected void setSpan_internal(Object span, int start, int end, int flags) {
   ((Editable) mText).setSpan(span, start, end, flags);
 }
 protected void setCursorPosition_internal(int start, int end) {
   Selection.setSelection(((Editable) mText), start, end);
 }

No matter what I do, they don't appear like overridable methods in the CTRL+O dialog in Android Studio, and if I do manually the IDE linter complains that "Method is never used".

That is my code:

public class MaxLengthEditText extends AppCompatEditText {
    public MaxLengthEditText(Context context) {
        super(context);
    }

    public MaxLengthEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MaxLengthEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    protected void setSpan_internal(Object span, int start, int end, int flags) {
        final int textLength = getText().length();
        getText().setSpan(span, start, Math.min(end, textLength),  flags);
    }


    protected void setCursorPosition_internal(int start, int end) {
        final int textLength = getText().length();
        Selection.setSelection(getText(), Math.min(start, textLength), Math.min(end, textLength));
    }
}

What am I doing wrong here?

Alessandro
  • 3,666
  • 2
  • 28
  • 41
  • 1
    Add the @Override annotation for each method and see if the compiler then complains about something – Joakim Danielson Oct 26 '19 at 14:14
  • Yes Joakim, it complains that that method is not overridable on superclass... I can't understand why... – Alessandro Oct 26 '19 at 14:36
  • 1
    Take a look at [this](https://stackoverflow.com/a/52760812/6950238) answer. Both `setSpan_internal()` and `setCursorPosition_internal()` marked as `@hide` in source code. – Andrii Omelchenko Oct 26 '19 at 15:13

0 Answers0