Android handle message runnable implements page update

Source: Internet
Author: User

I. Use handler and message to update the page

Private handler mhandler = new handler (){

Public void handlemessage (Message MSG ){
Switch (msg. What ){
Case 1: // Add functions
Int I = integer. parseint (textview. gettext () + "");
If (I> = 0 & I <= 90 ){
++ I;
Textview. settext ("" + I );
Textview. settextcolor (color. Black );
Relativelayout. layoutparams linearparams = (relativelayout. layoutparams) textview
. Getlayoutparams ();
Pbar. setprogress (I );
Linearparams. bottommargin = linearparams. bottommargin + 5; // go up

Textview. setlayoutparams (linearparams );
}

Break;

}
};

};

// Add a progress bar
Button2.setonclicklistener (New onclicklistener (){
Public void onclick (view v ){
Message message = new message ();
Message. What = 1;
Mhandler. sendmessage (Message );

}
});

Ii. Use of handler and runnable to update the page

Logoff. Prepare ();

Handler handler = new handler ();

Handler. Post (runnableui );

// Construct a runnable object and update the interface in runnable
Runnable runnableui = new runnable (){
@ Override
Public void run (){
// Update the interface
........

}

};

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.