0

In first run ,after opening the application it should wait for 1 second and open navigation drawer, after 1 second navigation drawer should close

SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(this);
    if (!preferences.getBoolean("Man",false))
    {

    // wait 1 second            

     DrawerLayout drawer = (DrawerLayout)  findViewById(R.id.drawer_layout);
        drawer.openDrawer(Gravity.LEFT);

   // wait 1 second

        DrawerLayout drawer = (DrawerLayout)  findViewById(R.id.drawer_layout);
        drawer.openDrawer(Gravity.RIGHT);

        SharedPreferences.Editor editor=preferences.edit();
        editor.putBoolean("Man",true);
        editor.commit();
    }
Nikhil PV
  • 1,014
  • 2
  • 16
  • 29
Jaison_Joseph
  • 333
  • 7
  • 26

3 Answers3

0

You can use Handler with recursion

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
}
Nitesh
  • 3,868
  • 1
  • 20
  • 26
0

You can either use 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();

Or Post Delayed,

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);
Lendl Leyba
  • 2,287
  • 3
  • 34
  • 49
0

You can use Handler to achieve wait time in your code

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