Android Simple Handler processing

Source: Internet
Author: User

1  Packagecom.example.androidprojecttest;2 3 ImportAndroid.os.Bundle;4 ImportAndroid.os.Handler;5 ImportAndroid.os.Message;6 ImportAndroid.os.Messenger;7 ImportAndroid. R.id;8 Importandroid.app.Activity;9 Importandroid.content.Intent;Ten ImportAndroid.view.Menu; One ImportAndroid.view.View; A ImportAndroid.view.View.OnClickListener; - ImportAndroid.widget.Button; - Importandroid.widget.LinearLayout; the ImportAndroid.widget.TextView; -  -  Public classMainactivityextendsActivity { -  +     PrivateTextView TView; -  +     PrivateHandler Mhandler =NewHandler () { A @Override at          Public voidhandlemessage (Message msg) { -             //TODO receives the message and goes to update the control content on the UI thread -             if(Msg.what = = 1) { - Tview.settext (string.valueof (msg.obj)); -             } -             Super. Handlemessage (msg); in         } -  to     }; +  - @Override the     protected voidonCreate (Bundle savedinstancestate) { *         Super. OnCreate (savedinstancestate); $ Setcontentview (r.layout.activity_main);Panax NotoginsengTView =(TextView) Findviewbyid (r.id.tv); -  the         NewThread () { +              Public voidrun () { A                 Try { the                      for(inti = 0; I < 100; i++) { +Thread.Sleep (500); -Message msgmessage=NewMessage (); $Msgmessage.what=1; $Msgmessage.obj= "The updated value is:" +i; - mhandler.sendmessage (msgmessage); -                     } the}Catch(Exception e) { - e.printstacktrace ();Wuyi                 } the             } - }.start (); Wu     } -  About}

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.