Android getchildat (INDEX) returns NULL. solution)

Source: Internet
Author: User
1 Handler handler = new Handler();        2         handler.postDelayed(new Runnable() {            3             public void run() {4                 // TODO Auto-generated method stub5                 gv.getChildAt(5).findViewById(R.id.tv).setBackgroundColor(Color.BLUE);6             }7         }, 500);

The Master said that the setadapter () method is not executed immediately, but uses the computer time slice rotation rule. Therefore, if the getchildat (INDEX) method is executed with a slight delay, no null is returned. However, this latency method is not an appropriate method when the product is created. If a user executes a large number of programs in the background, the CPU efficiency is very low, and the setadapter () is not completed for several time slices () method, which becomes a bug. If the latency is extended, it will affect the user experience.

Therefore, in general, it is necessary to change the status of a certain item of the gridview (such as changing the background), and this change is not triggered with the event (Click Event, select event, etc ), instead, you should first define the adapter and rewrite its getview () method so that you can complete the task directly at setadapter, you do not need to manually change it in the code. If dynamic changes are required, the onitemxxxlistener method can be implemented.

Transferred from: http://www.cnblogs.com/Couch-potato/

Related Article

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.