我有相同文本的editText视图。在我的路上,用户可以在editText中触摸char。如何检测char用户创建触摸事件?
答案 0 :(得分:1)
覆盖触控方式
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Layout layout = ((TextView) v).getLayout();
int x = (int)event.getX();
int y = (int)event.getY();
if (layout!=null){
int line = layout.getLineForVertical(y);
int characterOffset = layout.getOffsetForHorizontal(line, x);
Log.i("index", ""+characterOffset);
}
return true;
}
来源here