I don't want the user to insert anything in the middle of the EditText box. I only want to allow the user to click on the EditText box to bring out the keyboard, and insert at the end of the EditText box.
Is there a way to disable the ability for the user to change the cursor position when clicking on the EditText box?
I don't mind if the answer if done in XML or Java.
Thank you :)
Edit: if I have to use setSelection, is there a way to detect when the EditText box is clicked? so that I can set the cursor back to the end when the user click on the EditText.
you just need to set gravity to the right
You can use either the xml attribute
android:cursorVisible="false"
or the java functionsetCursorVisible(false)
.You can apply this trick, This worked for me. Just disable the cursor from edittext and on its click listener add your code that will keep the cursor on right most.
Here is code that i tried.
Java Code
Hope it will help you.
Use setSelection to set the cursor position. But that won't lock the insertion point. You can tell if someone changes the selection if you create a custom view and subclass EditText to override setSelectionChanged to force a different change to your liking. You may also want to override onTextChanged to verify that any change that happens does not break your rules.