textView and cursor position (change event) - like "onSelectionChanged"


#1

Hi. I’am trying to catch the cursor-position-change event. In native android i can use the method “onSelectionChanged”, but how can i do that in nativescript?

Example: i have a TextView (EditText in Android) and i would try to check the text at the current cursor position.

for example in Android i have my own EditText class (MyEditText)

snippet from activity_main.xml:

snippet from MyEditText (extends EditText):

@Override    
protected void onSelectionChanged(int selStart, int selEnd) 
{
    super.onSelectionChanged(selStart, selEnd);
    Log.i("MyEditText", "onSelectionChanged: " + selStart + " - " + selEnd);
}

now every cursor changing produces a log entry…
onSelectionChanged: 420 - 420
onSelectionChanged: 207 - 207
onSelectionChanged: 156 - 156

now i have the position in the text and i could test / check the text or anything else

is there another way to do this in nativescript?


#2

youd have to create a custom android.widget.TextView and override the onSelectionChanged method.


#3

you are right, but i try to avoid this solution because i have to copy a huge amount of code from nativescript modules (textView + editable-text-base) --> the EditableTextBase create the ui…

this._android = new android.widget.EditText(this._context);

is there a better way to do this?

possible solution / change in nativescript components?
==> separate the creation of the android components … for example:

EditableTextBase.prototype._createUI = function () {
this._android = this._createNativeUIElement();

}
EditableTextBase.prototype._createNativeUIElement = function() {
return new android.widget.EditText(this._context);
}

after that i can override the “_createNativeUIElement” method to provide my custom android widget element