In Android, viewgroup. removeview is called in the onanimationend method, and a solution for nullpointerexception is reported.

Source: Internet
Author: User

Original translated from: http://www.cxyclub.cn/n/16666/

After implementing the fade-out effect in Android development, the viewgroup is called in the onanimationend method when an image control is removed from the interface. removeview: It took me a long time to solve the nullpointerexception problem and finally found a solution in a foreigner's forum.

The direct execution method is usually as follows:

@ Override

Public void onanimationend (animation arg0 ){

// Remove the image when the animation ends.

Viewgroup. removeview (imageview );

}

However, the NULL pointer nullpointerexception may occur.

Later, we can see that the foreigner's method is to use handler to handle it, so no exception is reported, as shown below:

@ Override

Public void onanimationend (animation arg0 ){

// Remove the image when the animation ends.

// Viewgroup. removeview (imageview );

New handler (). Post (New runnable (){

Public void run (){

Viewgroup. removeview (imageview );

}

});

}

I would like to record it and hope it will be helpful to you.

Original translated from: http://www.cxyclub.cn/n/16666/

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.