android substuting the click with a timer

前端 未结 2 858
我在风中等你
我在风中等你 2021-01-24 14:33

I found this example and i have a small question: How can I remove the on click to a timer or a delay where it displays the first image and waits a couple of seconds then moves

2条回答
  •  我在风中等你
    2021-01-24 15:05

    No need for threads. Just use a Handler with postDelayed messages...

    public class HelloHandler extends Activity {
    
    protected Handler handler = new Handler();
    
    @Override
        public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           // blah blah blah
    
           handler.postDelayed(new UpdateTask(),500);
       }
    
    
       protected class UpdateTask implements Runnable {
       public void run() {
          // Do stuff.  This is UI thread.
          handler.postDelayed(this, 500);
       }
    }
    }
    

提交回复
热议问题