Android Edit Text - Cursor stays at the starting position

前端 未结 5 1191
野趣味
野趣味 2021-01-19 03:03

I am using an Edit Text in my project.

The problem is that whenever I type anything into the text box, it shows up, but the cursor does not move from its starting po

5条回答
  •  渐次进展
    2021-01-19 03:20

    Are you binding you view to a model? i.e. Do you have an MVVM setup?

    If you do, make sure you do not have any cyclical update especially for a two-way binding i.e. if user types a character, you update your model which will in turn update the EditText control and repeat.

    So depending on your Editext control properties, each time the model change updates it, it could have the cursor reset to the start position.

    If this is the case, a simple equality check between the model value and the EditText text value before you update it from the model should fix the issue.

    if (txtEdit.text != modelValue)
    {
        txtEdit.text = modelValue;
    }
    

提交回复
热议问题