Android click on the text in EditText, how to get the specific location of the current text in the input text?

Android click on the text in EditText, how to get the specific location of the current text in the input text?

Apr.16,2021

use editText.setSelection (Edittext.length ())

)

Example

EditText editText = findViewById(R.id.editText);
editText.setSelection(editText.getText().length());

use this method to disable popping up of the system keyboard, call the custom keyboard, and return false, in the setOnTouchListener event of editext otherwise the cursor cannot be moved to the position where the finger is clicked.
private void showEditText (EditText edit) {

    if (android.os.Build.VERSION.SDK_INT <= 10) {//4.0
        edit.setInputType(InputType.TYPE_NULL);
    } else {
        this.act.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        try {
            Class<EditText> cls = EditText.class;
            Method setShowSoftInputOnFocus;
            setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus",
                    boolean.class);
            setShowSoftInputOnFocus.setAccessible(true);
            setShowSoftInputOnFocus.invoke(edit, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Menu