So I ended up solving this via the link in James Moore's comment here. I ended up using the Tony Blues's solution in that link. That solution is this:
1.) Set an onTouchListener to the TextView.
2.) Get the layout of the TextView.
3.) Get the x,y coordinates of the touch via the event.
4.) Find the line and offset (index) based on that event.
The following code example is how one would Log (in verbose) the index of a touch given a TextView named manip:
manip.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Layout layout = ((TextView) v).getLayout();
int x = (int)event.getX();
int y = (int)event.getY();
if (layout!=null){
int line = layout.getLineForVertical(y);
int offset = layout.getOffsetForHorizontal(line, x);
Log.v("index", ""+offset);
}
return true;
}
});
EDIT: Rahul Mandaliya has brought it to my attention that this code will fail if there is padding on the text view. Unfortunately, it has been a very long time since I've written any Android code, so I'm not sure how to update this answer to account for that. Intuitively, it seems like you could do some sort of check against the click event if you know the padding value. Sorry about not being able to be more helpful on this edge case. :-(
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…