I have a edittext in which some text are selected . I want to get only selected text from edittext on click of button .
Please suggest me usable link or sample code.
I have a edittext in which some text are selected . I want to get only selected text from edittext on click of button .
Please suggest me usable link or sample code.
EditText et=(EditText)findViewById(R.id.edit);
int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();
String selectedText = et.getText().toString().substring(startSelection, endSelection);
Kotlin
val startSelection: Int = editText.selectionStart
val endSelection: Int = editText.selectionEnd
val selectedText: String = editText.text.substring(startSelection, endSelection)
© 2022 - 2024 — McMap. All rights reserved.