views:

37

answers:

1
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 needs to be - Is there something shorter like myInput.insertTextAtCursor(myText) or is this the way everyone does it?

A: 

I don't think there is... but nothing prevents you from creating a utility method for this, if you find yourself repeatedly writing the same two lines.

JRL