Android toast bug

Source: Internet
Author: User

Toast is often used in actual use, and it is extremely invincible and convenient to use.CodeYou can do it.

 
  
  

Toast. maketext (This, "Content to be displayed", Toast. length_short). Show ();

If you only use this code, you will find that when you click it multiple times in a row, toast will be displayed for a long time, which is not a bug in the strict sense ~

The following method can be used to solve the problem: Only one fixed toast object is used. The maketext method will actually go to a new toast object each time and set it by using settext () and setduration, in this way, toast will be updated immediately:

// Define the variable in advance and only use this variable

 
Toast mytoast =NewToast (mcontext );

 
 

 
 

Layoutinflater inflate = (layoutinflater) mcontext. getsystemservice (context. layout_inflater_service );

View v = inflate. Inflate (COM. Android. Internal. R. layout. transient_notification, null );

// The setview here cannot be small. Of course, the set view can also be constructed from the layout XML written by itself.

 
Mytoast. setview (v );

// Set the displayed text

 
Mytoast. settext ("Display content");

// Duration

 
Mytoast. setduration (toast. length_short );

// Show

 
Mytoast. Show ();

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.