Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - get selection of text from EditText

I'm trying to implement a copy/paste function. How can I get a selection of text from an EditText?

EditText et=(EditText)findViewById(R.id.title);

blabla onclicklistener on a button:

int startSelection=et.getSelectionStart();
int endSelection=et.getSelectionEnd();

Then I'm stuck. Any ideas?

like image 916
Laise Avatar asked Jan 29 '10 15:01

Laise


1 Answers

Seems like you've already done the hard part by finding what the selected area is. Now you just need to pull that substring out of the full text.

Try this:

String selectedText = et.getText().substring(startSelection, endSelection);

It's just a basic Java String operation.

like image 154
Mark B Avatar answered Sep 27 '22 22:09

Mark B