Is this the right way to insert text into a cursor in Android?

myInput.setText(myInput.getText().replace(myInput.getSelectionStart(), myInput.getSelectionEnd(), myText));
myInput.setSelection(myInput.getSelectionStart() + myText.length(), myInput.getSelectionEnd() + myText.length())

I ask because I think this code is much longer than it should be. Is there something shorter like myInput.insertTextAtCursor(myText), or is it the way everyone does it?

+3
source share
1 answer

I do not think that there is ... but nothing prevents you from creating a utility method for this if you find that you write the same two lines several times.

0
source

Source: https://habr.com/ru/post/1747878/


All Articles