Causes and solutions of invalid requestfocus() in Android Development
preface
Recently, when I was working on a company project, I often encountered a problem, that is, when I set requestfocus () for a control such as EditText, it didn't work. For example, when I logged in, I judged the password entered by the user. If it was correct, I would log in, and if it was wrong, I would prompt the wrong password, and the input box would get the focus, but it didn't work in practice
reason
After checking and analyzing the data, it may be the following problems:
Android loads and refreshes the UI from left to right and from top to bottom. If requestfocus() is being loaded, the entire interface may not be refreshed at this time, resulting in invalid requestfocus.
terms of settlement
After finding the cause, there will be a solution. Give him a delay:
This solves the problem.
PS: reason why requestfocus() is invalid
That is, requestfocus () should be placed after setvisible (true).
The above is the reason why requestfocus () is invalid in Android development and the solution introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!