如何在android中使用wait函数?

时间:2016-09-28 08:11:23

标签: android navigation-drawer delay wait

在第一次运行中,打开应用程序后应等待1秒并打开导航抽屉,1秒后导航抽屉应关闭

SELECT translate(NAME,'[0-9]-/^%#-$&&!_. ','[0-9]') last_names FROM table

3 个答案:

答案 0 :(得分:0)

您可以将Handler与递归

一起使用
boolean firstOpen = false;
public void animateDrawer(){
    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                         if(!firstOpen)
                           {
                             // open your Drawer here
                             firstOpen = true;
                             animateDrawer();
                           }
                           else
                           {
                             // close your Drawer here
                           }
                        }
                    },1000);
//1000 is a 1 second delay
}

答案 1 :(得分:0)

您可以使用CountDown Timer

new CountDownTimer(30000, 1000) {

    public void onTick(long millisUntilFinished) {
        mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
       //here you can have your logic to set text to edittext
    }

    public void onFinish() {
        mTextField.setText("done!");
    }

}.start();

或延迟发布,

final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
      @Override
      public void run() {
        //Do something after 100ms
        Toast.makeText(c, "check", Toast.LENGTH_SHORT).show();  
        handler.postDelayed(this, 2000);
      }
    }, 1500);

答案 2 :(得分:0)

您可以使用Handler在代码中实现等待时间

Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    // Actions to do after 1 second
                }
            }, 1000);