Whenever i touch the edittext, cursor should be at end.Even if the editText is already having some text and it should not allow to move left awards
editTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
editTextView.onTouchEvent(event);
if(!textFocus) {
editTextView.setSelection(editTextView.getText().length());
textFocus = true;
}
return true;
}
});
editTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
textFocus = false;
}
});
setSelection(editText. getText(). length()); This places cursor to end of EditText.
How do I change the cursor position in EditText? Say in your xml's edittext section, add android:paddingLeft="100dp" This will move your start position of cursor 100dp right from left end. Same way, you can use android:paddingRight="100dp" This will move your end position of cursor 100dp left from right end.
In android, we can set the text of EditText control either while declaring it in Layout file or by using setText() method in Activity file.
This is helped me. Always when i touch the edittext the cursor will be at the end
editTextView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
editTextView.onTouchEvent(event);
editTextView.setSelection(editTextView.getText().length());
return true;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With