Android EditText的requestFocus()什么时候做
我在滚动视图中有许多 EditText。在后台,这些字段链接到许多其他字段,并且布局定期(大约一秒一次)根据 EditText 中的值更新其文本字段。
问题是,如果一个 EditText 的焦点位于 ScrollView 的顶部,并且用户滚动视图完成(即聚焦的 EditText 离开屏幕),但如果对视图进行更新,则滚动视图会向上移动以聚焦视图顶部的 EditText。
我最接近解决这个问题的方法是使滚动视图在滚动时改变焦点,但这仍然具有相同的行为,但比例缩小了。
有谁知道我该如何阻止这种情况发生?
干杯, 马特
I have a number of EditTexts inside a scrollview. In the background these fields are linked to a number of other fields and regularly (once a second or so) the layout has it's textfields updated depending on the values in the EditText.
The problem is if one EditText has focus at the top of the ScrollView and the user scrolls the view done (i.e. so the focused EditText is off screen), but if the update is made to the views, the scroll view moves up to focus on the EditText at the top of the view.
The closest I have got to remedying this is to make the scroll view change focus when scrolling however this is still has the same behaviour but at a reduced scale.
Does anyone have an idea of how I can stop this from happening?
Cheers,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试在更新值的代码周围使用
EditText#setFocusable
。我还没有对此进行测试,但如果问题是当您使用setText()
时它会获得焦点,它可能会有所帮助。You can try using
EditText#setFocusable
around your code that updates the value. I haven't tested this but if the problem is that it is getting focus when you usesetText()
it may help.