I want build an app where I want to use selectable TextView. When user selects a text from TextView he will show this selectable text into other screen. But when I selected the text from TextView , I can not retrieve the selected text. I also use the method for TextView.
menu_search = (TextView)findViewById(R.id.menu_search);
menu_search.setTextIsSelectable(true);
How can I get the selected text from Select-able textview?
Is it possible for Android?
Try this
String str = menu_search.getText().toString;
int startIndex = menu_search.getSelectionStart();
int endIndex = menu_search.getSelectionEnd();
String selectedStr = str.subString(startIndex, endIndex);
It should be possible to to the following:
int selection_start = menu_search.getSelectionStart();
int selection_end = menu_search.getSelectionEnd();
String selected = menu_search.getText().toString().subSequence(selection_start, selection_end);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.