When requestfocus cannot work immediately...

Source: Internet
Author: User

I don't know if you have ever encountered such a situation: the first time you created an APK interface, you wanted to display requestfocus () in a certain place to get the focus, but you couldn't call it directly, as shown in 1.

Figure 1 focus position

This phenomenon occurs when Android loads and refreshes the UI, in the order from left to right, from top to bottom. During the loading process, if requestfocus (findviewbyid (c) at this time )), if the interface is not refreshed yet, the requestfocus is invalid.

So I thought of a clever method. First, the asynchronous latency was about ms (the human eyes could not feel the changes within ms), and then requestfocus. I tried it and it was OK. The Code is as follows, if you have a better method, please contact me. Thank you.

 
New handler (). postdelayed (New runnable () {@ override public void run () {requestfocus (specific ID) ;}, 200 );


For Original Articles, please refer to blog.csdn.net/jjzhoujun2010 for reprinting.

Dream fly


When requestfocus cannot work immediately...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.