EditText上的光标位置 [英] EditText's cursor position
问题描述
假设,用户已写了一些文字到的EditText ,然后摸别的地方在屏幕上,这引起了光标的位置更改:?怎样才能确定新的光标位置
Assuming, that a user has written some text into an EditText and thereafter touched somewhere else on the screen, which caused the cursor position to change: How can one determine the new cursor position?
推荐答案
简单的版本:
myEditText.getSelectionStart();
如果你想你可以尝试的事件作出反应。
If you want to react on an event you may try
myEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
// view is myEditText here
}
});
事件
允许presses和版本之间的区别。
event
allows to distinguish between presses and releases.
的EditText
也有 setOnClickListener()
这可能是值得关注一下。
EditText
also has a setOnClickListener()
that might be worth to look at.
编辑:
我忘了提 onSelectionChanged(INT SelStart的,INT selEnd)
,其中selEnd等于SelStart的,如果位置发生变化。
I forgot to mention onSelectionChanged(int selStart, int selEnd)
where selEnd equals selStart if the position changed.
这篇关于EditText上的光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!