당신은 그것을 EditText
에서 선택한 텍스트를 얻을 수있는이 방법을 수행 할 수 있습니다
EditText editText = (EditText) findViewById(R.id.editText3);
int min = 0;
int max = editText.getText().length();
if (editText.isFocused()) {
final int selStart = editText.getSelectionStart();
final int selEnd = editText.getSelectionEnd();
min = Math.max(0, Math.min(selStart, selEnd));
max = Math.max(0, Math.max(selStart, selEnd));
}
// here is your selected text
final CharSequence selectedText = editText.getText().subSequence(min, max);
String text = selectedText.toString();
출처
2015-05-08 07:19:55
SKG
안드로이드와 사소한 불만은 getSelectionStart()와 getSelectionEnd()가 아무튼 물건 선택한 순서를 의미한다는 것입니다 꼭 필요한 시작으로 끝나야합니다. (끝내지는 않겠지 만 여기에 몇 가지 OutOfBounds를 저장하는 것이 좋을 것입니다.) – andy
얘들 아, 내 대답과 비슷하지만 getselectionStart() 및 getSelectionEnd() 메서드 문제가있다. 둘 다 같은 값을 반환합니다. – FpontoDesenv
et.getText()는 수정 가능 항목을 반환합니다. substring()은 문자열을 반환합니다. toString()을 추가해야합니다. 그것은 - et.getText(). toString(). substring (start, end)입니다. – earlcasper