光标移动到输入文本的左侧,而不是蜂窝上的右侧
这是一个奇怪的问题。我们使用的 EditText 控件之一是将光标移动到键入文本的左侧而不是右侧。这只发生在 Honeycomb 上(相同的代码在 Gingerbread 上工作正常),并且只发生在这个特定的 EditText 控件中,并且仅发生在您第一次开始键入时。有什么想法吗?
<EditText android:id="@+id/preview_range_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:digits=",-0123456789"
android:maxLines="1"
android:singleLine="true"
android:layout_toRightOf="@id/preview_range_txt"
android:layout_toLeftOf="@id/preview_range_radio"
android:layout_centerVertical="true"/>
编辑补充说,经过一些额外的测试,我发现这仅在设备处于纵向而不是横向时才是问题。
This is a kind of strange problem. One of the EditText controls we are using is moving the cursor to the left of typed text instead of the right. This only happens on Honeycomb (same code on Gingerbread works fine) and it only happens in this particular EditText control and only the first time you start typing. Any ideas?
<EditText android:id="@+id/preview_range_edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:digits=",-0123456789"
android:maxLines="1"
android:singleLine="true"
android:layout_toRightOf="@id/preview_range_txt"
android:layout_toLeftOf="@id/preview_range_radio"
android:layout_centerVertical="true"/>
Edited to add that after some additional testing I found this is only a problem if the device is in portrait orientation, not in landscape.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我找到了答案,与我的布局无关。我的 EditText 控件的数据处理的一部分是调用一个 notificationDataSetChange ,它将焦点从我的 EditText 控件上移开,然后返回它,但在返回时它错误地重置了光标。这可能是操作系统中的一个错误。我的解决方法是将 OnFocusChangeListener 添加到我的 EditText 控件中,并在焦点丢失时存储光标,并在焦点返回时恢复光标。
So I found the answer, had nothing to do with my layout. Part of the processing of the data of my EditText control was calling a notifyDataSetChange that was taking the focus away from my EditText control and then returning it but on return it was resetting the cursor incorrectly. This is probably a bug in the OS. The workaround for me was to add an OnFocusChangeListener to my EditText control and store the cursor when focus was lost and restore the cursor when focus was returned.