Android Learning-interface-event-handler

Source: Internet
Author: User

After the Android program runs, the system generates a main thread, and if you modify the UI in the main thread, it will conflict, so Android recommends using handler to change the UI

1.4 Photos Timing Transform

 Public classMainactivityextendsActivity {ImageView imageView1; intIndex=0; int[] pics=New int[]{R.DRAWABLE.PIC1,R.DRAWABLE.PIC2,R.DRAWABLE.PIC3}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); ImageView1=(ImageView) Findviewbyid (R.ID.IMAGEVIEW1);        Thread.Start (); } Thread Thread=NewThread () { Public voidrun () {Try {                 while(true) {Sleep (1000); Hand.sendemptymessage (12345); }            } Catch(interruptedexception e) {//TODO Auto-generated catch blockE.printstacktrace ();    }        }    }; Handler Hand=NewHandler () { Public voidhandlemessage (Message msg) {if(msg.what==12345) {Imageview1.setimageresource (Pics[index%3]); Index=index+1;    }        }    }; }
View Code

Android Learning-interface-event-handler

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: 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.