如何在 EditText
中的光标位置插入一段文字? editText.setText
删除当前文本并设置新文本,这不是我想要的。 editText.setText(editText.getText() + "my text");
在末尾插入文本,也不是这种情况。
最佳答案
这很容易做到:
int start =editText.getSelectionStart(); //Get cursor position with this function
String str = "my text";//String you want to insert
editText.getText().insert(start, str); //This will get the text and insert the String str at the current position.
希望对您有所帮助!
关于java - 如何在 EditText 中插入文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27723002/