3

something like this ...

setContentView(R.layout.page1);
Thread.sleep(1000);
setContentView(R.layout.page2);
ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
drdrdr
  • 2,788
  • 4
  • 17
  • 16

4 Answers4

12

Use a CountDownTimer, see http://developer.android.com/reference/android/os/CountDownTimer.html

Import android.os.CountDownTimer;


setContentView(R.layout.page1);
new CountDownTimer(1000, 1000) {

   public void onTick(long millisUntilFinished) {
   }

   public void onFinish() {
       setContentView(R.layout.page2);
   }

}.start();
drdrdr
  • 2,788
  • 4
  • 17
  • 16
Stefan H Singer
  • 5,469
  • 2
  • 25
  • 26
  • thank you very much your code worked. just needed to import android.os.CountDownTimer and type CountdownTimer as CountDownTimer, with capital D. – drdrdr Sep 18 '11 at 13:44
  • Excellent. Got to love that the typo came from copy pasting from the documentation (they didn't use a capital D :)). – Stefan H Singer Sep 18 '11 at 17:05
4

You can use:

 SystemClock.sleep(100); //ms
Martin Koubek
  • 433
  • 4
  • 8
3

you can also use postDelayed(new Runnable(), 1000); add the action you want to do in the runnable.

Yashwanth Kumar
  • 28,931
  • 15
  • 65
  • 69
1

The proper way should be:

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    //Do something after 2s
  }
}, 2000);

This question has already answer here

Carlos Daniel
  • 2,459
  • 25
  • 30