title: Countdown timer which has increment/decrement option that can be set by user
body: <p>I’m new to Java language but worked with C language previously. I tried many ways to solve the following problem but couldn’t so I need help. 
  I’m trying to do the following:</p>
  
  <p>•Set 5 minute timer (counter) as default so starts when Start_button is pressed.</p>
  
  <p>•If Start_button is not pressed and the user presses  Up_button /Down_button then display timer options on screen; 5, 10 and 15minutes and if the user presses Starts_button it starts to count down the timer chosen.  </p>
  
  <p>•While timer is running;</p>
  
  <pre><code>  •If Up_button /Down_button is pressed once then reset timer and show previous time setting i.e. 5, 10 or 15minutes.
    •If Up_button /Down_button is pressed again then display timer options on screen and if the user presses Starts_button it starts the timer chosen.  
  </code></pre>
  
  <p>At the moment; the timer is working once Start is pressed it counts down the 5 minutes. But I do not know the best way to display the timer options and also start the chosen timer.</p>
  
  <p>Your help is appreciated, thank you very much in advance.</p>
  
  <p>As mentioned above; I’m in the process of learning Java programming so take it easy on me ;-)   and show me the code that you think is best for this problem please</p>
  
  <p>This is what I did so far:</p>
  
  <pre><code>public class Test extends Activity {
  
  // Display Counter Variables
  public static Button Up, Down, Green;
  
  TextView timeDisplay;
  MyCount counter, counter1, counter2;
  int state = 0;
  int length = 300000; //5minutes
  int length1 = 600000; //10minutes
  int length2 = 900000; //15minutes
  long startTime = 0;
  long currentTime = 0;
  long timeElapsed = 0;
  long timeRemaining = 0;
  long prevTimeRemaining = 0;
  boolean up_pressed = false;
  boolean down_pressed = false;
  private boolean timerStarted=false;
  
  Button start;
  
    public String formatTime(long millis) {
          String output = "";
          long seconds = millis / 1000;
          long minutes = seconds / 60;
  
          seconds = seconds % 60;
          minutes = minutes % 60;
  
          String secondsD = String.valueOf(seconds);
          String minutesD = String.valueOf(minutes);
  
          if (seconds &lt; 10)
            secondsD = "0" + seconds;
          if (minutes &lt; 10)
            minutesD = "0" + minutes;
  
          output = minutesD + " : " + secondsD;
          return output;
        }
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.test);
  
  
      timeDisplay = (TextView) findViewById(R.id.timer);
      counter = new MyCount (length, 1000);
      counter1 = new MyCount (length1, 1000);
      counter2 = new MyCount (length2, 1000);
  
      start = (Button) findViewById(R.id.Button);
      Up = (Button)findViewById(R.id.Yellow);
      Down = (Button)findViewById(R.id.Blue);
  
  
  
  start.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
          switch (state) {
          case 0:
            startTime = System.currentTimeMillis();
              counter.start();
              timerStarted=true;
              start.setText(R.string.pause);
                state=1;
  
            break;
  
         case 1:
            // pause
            currentTime = System.currentTimeMillis();
            timeElapsed = currentTime - startTime;
            if (prevTimeRemaining == 0)
              timeRemaining = length - timeElapsed;
            else
              timeRemaining = prevTimeRemaining - timeElapsed;
            counter.cancel();
            timeDisplay.setText("" + formatTime(timeRemaining));
            start.setText(R.string.resume);
            prevTimeRemaining = timeRemaining;
  
            // resume
            counter = new MyCount(timeRemaining, 1000);
            state = 0;
            break;
  
          case 2:
            prevTimeRemaining = 0;
            timerStarted=false;
            counter = new MyCount(length, 1000);
            start.setText(R.string.start);
            timeDisplay.setText(R.string.timer);
            state = 0;
          }
      }
  });
  
  
      Up.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              down_pressed=true;
  
              if(up_pressed=true &amp;&amp; timerStarted==true 
                  || timerStarted==false){
                  //Display timer (increment i.e. show 5min --&gt; 10min ..&gt; 15min)
  
                  //start timer chosen by user
              }
  
          }
      });
  
  
      Down.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              down_pressed=true;
              if(down_pressed=true &amp;&amp; timerStarted==true 
                  || timerStarted==false){
                  //Display timer (decrement i.e. show 15min --&gt; 10min ..&gt; 5min)
  
                  //start timer chosen by user
              }
          }
      });
  }
  
  
    public class MyCount extends CountDownTimer {
  
        public MyCount(long millisInFuture, long countDownInterval) {
          super(millisInFuture, countDownInterval);
        }
  
        public void onFinish() {
          timeDisplay.setText("done!");
          state = 2;
         start.setText(R.string.restart);
        }
  
        public void onTick (long millisUntilFinished) {
          timeDisplay.setText ("Left: "  + formatTime(millisUntilFinished));
  
        }
  
      }
  </code></pre>
  
  <p>}</p>