I have a TextView
with an OnTouchListener
. What I want is the character index the user is pointing to when I get the MotionEvent
. Is there any way to get to the underlying font metrics of the TextView
?
Have you tried something like this:
Layout layout = this.getLayout();
if (layout != null)
{
int line = layout.getLineForVertical(y);
int offset = layout.getOffsetForHorizontal(line, x);
// At this point, "offset" should be what you want - the character index
}
Hope this helps...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With