I use the following code to set the cursor
at the end
of customEditText(EditText
) but it brings no effect.
customEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
String customEditTextText = customEditText.getText().toString();
int selection = customEditTextText.length();
customEditText.setSelection(selection);
}
}
});
Has anybody any ideas for that ?
The main layout of the application contains the EditText Widget and two buttons. To implement the UI invoke the following code inside the activity_main.xml file. To get an idea about how the basic EditText in android looks like. 1. Input Type for the EditText This is one of the attributes which is needed to be specified under the EditText widget.
1. Input Type for the EditText InputType Attribute Type of the Data which is entered number Mathematical numeric value phone Contact Number based on the country code date To take the date input time To take the time is neededinput 8 more rows ...
Provide the EditText with the id, by referring to the following code, which has to be invoked inside the activity_main.xml file. The following code needs to be invoked inside the MainActivity.kt file. Which performs the retrieving operation and provides the Toast message the same as the entered data.
I had the same issue with an EditText inside an AlertDialog. The solution for me was this:
mEditText.post(new Runnable() {
@Override
public void run() {
mEditText.setSelection(mEditText.length());
}
});
Works for me:
editText.requestFocus();
editText.setSelection(editText.getText().length());
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