I'd like to position a widget at the cursor position of an EditText
widget.
This will be a widget on top of the cursor - to move as text is
entered into the EditText widget.

Currently, I'd using a TextChangedListener and rendering the text
locally to figure the pixel position.
Painting the text just to figure the pixel width seems wasteful.
Wondering if there is a better way to do this?

The code segment of interest -

EditText entry;
entry.addTextChangedListener(new TextWatcher() {
    ....
    public void afterTextChanged(Editable s) {
        String s = entry.getText().toString();
        TextPaint p = new TextPaint();
        p.setTextSize(entry.getTextSize());
        Rect r = new Rect();
        p.getTextBounds(s, 0, s.length(), r);
        // using r.width() to get the position of interest.
   }
}

thanks,
-sr

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to