title: How to put 4-seconds delay while changing the background image of a buttan in Android
body: <p>I have two buttons in my sample application and I want to change the background image of the buttons one after another with 4-seconds delay, So far i have developed the code, you can see it below, but it gets sleep  my application and display nothing.</p>
  
  <p>Please somebody help me that I could do so. </p>
  
  <pre><code>   int m =0;
      int delay = 4;  //Seconds
  
      while(m &lt; 4)
      {
  
  
  
       // int i = (int) (Math.random() * num + 1);
  
      if(m==0)
      {
          button1.postDelayed(new Runnable()
          {
              public void run()
              {
              // TODO Auto-generated method stub
              button1.setBackgroundResource(R.drawable.buttonyellow);
              m++;
              }
          }, 1000*delay);
  
      }
  
  
      else if(m==1)
      {
          button2.postDelayed(new Runnable()
          {
              public void run()
              {
                  // TODO Auto-generated method stub
                  button2.setBackgroundResource(R.drawable.buttonyellow);
                  m++;
              }
          }, 1000*delay);
  
      }
  
  
  
  
  
      if(m==2)
      {
          button1.postDelayed(new Runnable()
          {
              public void run()
              {
              // TODO Auto-generated method stub
              button1.setBackgroundResource(R.drawable.buttonblue);
              m++;
              }
          }, 1000*delay);
  
      }
  
  
      else if(m==3)
      {
          button2.postDelayed(new Runnable()
          {
              public void run()
              {
                  // TODO Auto-generated method stub
                  button2.setBackgroundResource(R.drawable.buttonblue);
                  m++;
              }
          }, 1000*delay);
  
      }
  
  
  
      }
  </code></pre>