【发布时间】:2012-04-21 16:21:34
【问题描述】:
我有一个编辑文本,其中选择了一些文本。我只想在单击按钮时从 edittext 中获取选定的文本。
请给我推荐可用的链接或示例代码。
【问题讨论】:
标签: android android-layout android-intent android-emulator android-widget
我有一个编辑文本,其中选择了一些文本。我只想在单击按钮时从 edittext 中获取选定的文本。
请给我推荐可用的链接或示例代码。
【问题讨论】:
标签: android android-layout android-intent android-emulator android-widget
EditText et=(EditText)findViewById(R.id.edit);
int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();
String selectedText = et.getText().toString().substring(startSelection, endSelection);
【讨论】:
getSelectionStart()
getSelectionEnd()
看到这个link
【讨论】:
科特林
val startSelection: Int = editText.selectionStart
val endSelection: Int = editText.selectionEnd
val selectedText: String = editText.text.substring(startSelection, endSelection)
【讨论】: