So, I have an EditText view and my idea is on a, lets say for now, touch event to select and copy the touched word into clipboard memory. So far I can set Selection through offset, but it is only ""
, because getSelectionStart() = getSelectionEnd() = offset
. How can I extend it until the next encountered whitespace or end/start of text.
How could I extend one such selection in the above described manner?
Code so far:
@Override
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN) {
float x = event.getX() + getScrollX();
int offset = getOffset(event);
if(offset != Integer.MIN_VALUE){
setSelection(offset);
String selectedText = getText().toString()
.substring(getSelectionStart(), getSelectionEnd());
//TODO: extend selection otherwise copies ""
putInClipMemory(selectedText);
}
return true;
}
Thanks.