8

Is there any way to map characters to a pixel location in an EditText?

I assume there is some knowledge within the component of the word at any pixel location, because you can select a word for copy and paste operations.

Also, most of the popular browsers and book readers have some sort of lookup function where you can select a word and look it up on the web or in a dictionary. How do these apps know the word that was tapped or selected?

I can't think of a good strategy for accomplishing this, beyond re-writing EditText and capturing all of the entered text as they are rendered in the onDraw() method.

I am sure there must be a much better strategy than that! Any ideas?

Dan D.
  • 73,243
  • 15
  • 104
  • 123
Victor Grazi
  • 15,563
  • 14
  • 61
  • 94
  • Any reason why you are looking for pix level? If you want to findout selcted text in edit text, there are methods you can use. – kosa Jan 08 '12 at 03:49
  • I guess I only need the selected text. I tried using a ClickableSpan but the problem with that was I need to detect the amount of time the user presses the word - ClickableSpan is like a web link, it responds instantly, which is no good for my purposes. But I am not seeing methods to detect the selected word - can you please advise? – Victor Grazi Jan 08 '12 at 06:35
  • 1
    See if this SO discussion may be helpful http://stackoverflow.com/questions/2163017/android-get-selection-of-text-from-edittext – kosa Jan 08 '12 at 06:38
  • Yup, thanks, that should do the trick! – Victor Grazi Jan 08 '12 at 07:18

1 Answers1

1

Try this:

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

It's just a basic Java String operation.