开发者

Cursor location not updated when non-focused EditText clicked

开发者 https://www.devze.com 2023-01-21 18:40 出处:网络
When non-focused EditText clicked, 开发者_StackOverflow社区it becomes focused, but cursor does not move to new location. I should click it again to move cursor to a new position.

When non-focused EditText clicked, 开发者_StackOverflow社区it becomes focused, but cursor does not move to new location. I should click it again to move cursor to a new position.

Q: How can I focus and move cursor with only one click?


I spent quite some time battling the same problem, and this is what I did:

In your layout xml, enable focusable and focusableInTouchMode

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:focusable="true" android:focusableInTouchMode="true">
</LinearLayout>

Otherwise, whenever the softkeyboard comes up, it automatically scrolls to the front of the EditText. You can modify the position by overriding "OnFocusChangeListener" but it's a little ugly to poll the clicked position every time. I'm going to stick with the change above.

0

精彩评论

暂无评论...
验证码 换一张
取 消