gpt4 book ai didi

java - 如何从可选择的 TextView 中获取文本字符串?

转载 作者:行者123 更新时间:2023-11-29 05:46:30 25 4
gpt4 key购买 nike

我想构建一个应用程序,我想在其中使用可选择的 TextView。当用户从 TextView 选择一个文本时,他会将这个可选择的文本显示到其他屏幕中。但是当我从 TextView 选择文本时,我无法检索所选文本。我也使用 TextView 的方法。

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

menu_search.setTextIsSelectable(true);

如何从可选择的 TextView 中获取选定的文本?

Android 有可能吗?

最佳答案

试试这个

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

关于java - 如何从可选择的 TextView 中获取文本字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15703337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com