[英]How do I prevent cursor from placing itself at the beginning of EditText when clicked
I have an EditText pageTitle
and its behavior is dependent on its onFocusListener
and onClickListener
and another method setListenerToRootView()
which detects if the soft keyboard is shown or hidden. 我有一个EditText pageTitle
和其行为取决于其onFocusListener
和onClickListener
和另一种方法setListenerToRootView()
其检测是否被显示或隐藏软键盘。 The issue is whenever I click pageTitle
, the cursor is automatically placed at the beginning. 问题是,每当我单击pageTitle
,光标就会自动放置在开头。 I am suspecting setListenerToRootView()
is responsible for this bug since issue fixes itself when I remove this method. 我怀疑setListenerToRootView()
是造成此错误的原因,因为删除此方法后问题会自行解决。
However, I do need this method since another view's visibility ( saveCancelBar
) depends on the soft keyboard's visibility. 但是,我确实需要此方法,因为另一个视图的可见性( saveCancelBar
)取决于软键盘的可见性。 Is there any way that I can keep this method but make sure that when the user clicks pageTitle
, the cursor will be placed on the exact position that he clicked (not the beginning)? 有什么方法可以保留此方法,但是要确保当用户单击pageTitle
,光标将位于其单击的确切位置(而不是开头)?
use setSelection()
for selecting the last position programatically. 使用setSelection()
以编程方式选择最后一个位置。 in onClick
and onFocus
use setSelection 在onClick
和onFocus
使用setSelection
editTextName.setSelection(editTextName.getText().length());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.