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.
We have used getText() method to get the text entered in the EditText views. But getText() method returns an Editable instance and therefore we have typecasted it to convert it into String for further use. This can be done by using the toString() method.
To enable text in TextView for selection, set android:textIsSelectable attribute to “true” for the TextView widget in layout XML file.
TextView is the widget used when you want the user to View the Text (such as a label, etc) and EditText used when you want the user to be able to edit the text. The text in either widget can be set programmatically or via xml using the android:text parameter.
EditText et=(EditText)findViewById(R.id.edit);
int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();
String selectedText = et.getText().toString().substring(startSelection, endSelection);
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