java - ListView中的EditText在输入到行末自动换行的时候总是失去焦点
PHPz
PHPz 2017-04-18 10:31:30
0
2
687

Situation:
LiveView中的Item都是一个自定义的View,其中有一个EditText控件用于输入文字。现在输入的过程中一旦到了一行的末尾自动换行的时候,焦点就失去了,要重新点击该EditText控件才可以继续输入。

为什么会这样,是因为listview重新绘制了嘛?怎么解决。。

PHPz
PHPz

学习是最好的投资!

reply all(2)
小葫芦

The listview has been redrawn. The whole process has been redrawn three times. Clicking the edittext soft keyboard pops up, which causes the listview to be compressed. This is the first time. Too many edittext content and line breaks cause the edittext height to change, which further causes the item height to change. It needs to be redrawn. This is the first time. Second time; redrawing will cause the edittext to lose focus, the soft keyboard is hidden, the listview is expanded, and the third redrawing is performed. So, do you already know the solution? Since it is caused by losing focus, then get the focus again, record the edittext of the last operation, and check it in the adapter's getView method. If it is this edittext, requestFocus.

刘奇

Scrolling of ListView prompts it to re-LayoutChildren, and finally causes EditText to lose input focus.
Since EditText will not adapt to ListView, it is recommended to change to RecyclerView...

p.s. There are few apps in the app market that are designed like this: Put an EditText in ListView...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!