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}