2013-03-29 54 views
1

我想创建一个应用程序,我想使用可选的TextView。当用户从TextView中选择一个文本时,他会将这个可选文本显示到其他屏幕上。但是当我从TextView中选择文本时,我无法检索选定的文本。我也使用TextView的方法。如何从可选的TextView中获取文本字符串?

menu_search = (TextView)findViewById(R.id.menu_search); 

menu_search.setTextIsSelectable(true); 

如何从Select-able textview中获取选定的文本?

Android可能吗?

+1

您可以通过添加机器人让你的TextView可选:textIsSelectable =直接在您的布局xml文件“真”。 – JJ86

回答

2

试试这个

String str = menu_search.getText().toString; 
int startIndex = menu_search.getSelectionStart(); 
int endIndex = menu_search.getSelectionEnd(); 
String selectedStr = str.subString(startIndex, endIndex); 
1

应该可以向以下:

int selection_start = menu_search.getSelectionStart(); 
int selection_end = menu_search.getSelectionEnd(); 
String selected = menu_search.getText().toString().subSequence(selection_start, selection_end); 
相关问题