title: Android User input to countdown timer
body: <p>I'm working on a countdown timer with user input on how many seconds to count down.</p>
  
  <pre><code> private void showTimer() {
          myString = ((EditText)editTextTimer).getText().toString();
          int countdownMillis = Integer.parseInt(myString) * 1000;
  
          if (timer != null) {
              timer.cancel();
          }
          timer = new CountDownTimer(countdownMillis, MILLIS_PER_SECOND) {
  
              @Override
              public void onTick(long millisUntilFinished) {
                      ((TextView) countdownDisplay).setText("Counting down: " +
                              millisUntilFinished / MILLIS_PER_SECOND);
                      ((TextView) countdownDisplay).setTextSize(25);
              }
              @Override
              public void onFinish() {
                  ((TextView)countdownDisplay).setText("Time's Up !");
                  ((TextView)countdownDisplay).setTextSize(25);
              }
          }.start();
  
  
      }
  </code></pre>
  
  <p>I'm doing this on a fragment. The problem is the text display of the "Time's Up" after I insert the time and click start. When clicking start again the timer will just start to display and countdown. As well the timer sometimes will skip 1 second. </p>
  
  <p>Example user insert 10. 
  It will countdown from 10 , 9 , 7, 6, 5, 4, 3, 2, 1  - 8 is missing.</p>
  
  <p>onCreatView</p>
  
  <pre><code>  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_countDown, container, false);
  
          countdownDisplay = rootView.findViewById(R.id.txtTimerLeft);
          editTextTimer = rootView.findViewById(R.id.txtTimer);
          startbutton = rootView.findViewById(R.id.button_start1);
  
          startbutton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View view) {
                  try {
                      showTimer();
                  } catch (NumberFormatException e) {
  
                      e.printStackTrace();
                  }
              }
          });
  
  
          return rootView;
      }
  </code></pre>
  
  <p>Declaration</p>
  
  <pre><code> View editTextTimer;
      View startbutton;
      private static final int MILLIS_PER_SECOND = 1000;
      int SECONDS_TO_COUNTDOWN;
      View countdownDisplay;
      private CountDownTimer timer;
      String myString;
  </code></pre>