title: How can I make a piece of code loop while a Button is pressed and stop it once the Button is no longer Pressed?
body: <p>I am using the android developer tools in Eclipse, programming in Java, and I need to make an object move across the screen as long as a button is pressed.  I've been doing research for hours, and I cannot find any methods to accomplish this.  I've tried running threads, which often crash or seemingly don't execute.  I've also tried an <code>onClickListener</code> which reads the button state and uses it to determine whether or not the button is still pressed.  I'm currently using a while loop, but this just freezes the program.  I believe that this is the best method, and I've tried to use Thread.sleep in order to limit the number of iterations per second, as I believe that this is the reason it is freezing. Am I on the right track or am I way off in left field?  Here is a snippet of code:</p>
  
  <pre><code>rightButton.setOnClickListener(new OnClickListener()
      {
  
          @Override
          public void onClick(View arg0) 
          {
              while(arg0.isPressed())
              {
                  mover.updateCoordinates(1,  0);
              }
          }
  
      }); 
  </code></pre>