How to set cursor to the end of text in EditText on Android?
Hello everyone! I'm a beginner Android developer in Java, and I've encountered a problem that I can't solve for several hours. I have an EditText where the user enters text, and a button "Add character". When the button is pressed, I add a specific character (e.g., "|") to the end of the EditText. The code looks like this:
```java
EditText editText = findViewById(R.id.editText);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String currentText = editText.getText().toString();
editText.setText(currentText + "|");
}
});
```
The problem is that after adding the character, the cursor (caret) automatically moves to the beginning of the text or stays where it was before the insertion.