I have EditText which displays something like ###-###. I want the user to be able to change this text only from the 1st position onward. That is user should not be able to touch
This will receive the on click event when the edit text doesn't have focus. so The user can click on the edit text to transfer the focus, and on focus change listener will update the cursor position to end.
cardNumberEditText.setOnTouchListener { v, event ->
return@setOnTouchListener cardNumberEditText.hasFocus()
}
cardNumberEditText.setOnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
cardNumberEditText.setSelection(
cardNumberEditText.text.length
)
}
}