Example of android latency Processing Task

Source: Internet
Author: User

Today, I want to do a task, ask for the picture button to switch, and click the corresponding event. Click to open the image. several lines of fonts are displayed on the left of the image, which are delayed. The main code is attached below. Main. xml

 

The following code is required for latency processing:

 

new Handler().postDelayed(new Runnable(){        public void run() {        //execute the task        }     }, delay); 


 

 

The java code MainActivity. java is as follows:

Package com. example. vieweffect; import android. app. activity; import android. app. actionBar; import android. app. fragment; import android. graphics. bitmap; import android. graphics. bitmapFactory; import android. OS. bundle; import android. OS. handler; import android. view. layoutInflater; import android. view. menu; import android. view. menuItem; import android. view. view; import android. view. view. onClickListener; import android. view. viewGroup; import android. widget. imageButton; import android. widget. imageView; import android. widget. textView; import android. OS. build; public class MainActivity extends Activity {TextView txtview01; TextView txtview02; TextView txtview03; TextView txtview04; TextView txtview05; TextView txtview06; private ImageView start = null; protected boolean isBrewing = false; // button replacement @ Overrideprotected void onCreate (Bundle savedInstanceState) extends View06); start = (ImageView) findViewById (R. id. start); start. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stubif (v = start) {if (isBrewing) stopView (); else startView () ;}});} // start public void startView () {Bitmap bmp = BitmapFactory. decodeResource (getResources (), R. drawable. stop); // open the resource image start. setImageBitmap (bmp); txtview01.setText (open the serial port ...); new Handler (). postDelayed (new Runnable () {public void run () {// execute the task txtview02.setText (open ...);}}, 500); new Handler (). postDelayed (new Runnable () {public void run () {// execute the task txtview03.setText (open B ...);}}, 1000); new Handler (). postDelayed (new Runnable () {public void run () {// execute the task txtview04.setText (Open C ...);}}, 1500); isBrewing = true;} // stop public void stopView () {Bitmap bmp = BitmapFactory. decodeResource (getResources (), R. drawable. blue); // open the resource image start. setImageBitmap (bmp); txtview01.setText (); txtview02.setText (); txtview03.setText (); partial (); txtview06.setText (); isBrewing = false ;}}

The following page is displayed after running:

 

, Click the blue image,

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.