title: How to calculate charges based on timer in android?
body: <p>I'm trying to build an android app that does arithmetic calculation while the timer is running. How can I do it?</p>
  
  <p>This is the calculation class</p>
  
  <pre><code> public class CalculateCharges {
  
      private Double total = 0.0;
      private long secs,mins,hrs;
  
      public Double calculateTotal(long hours, long mins) {
  
          if (mins &lt; 1) {
              return total = 0.05;
          }
  
          if (mins == 1 || (mins &gt; 1 &amp;&amp; mins &lt; 2)) {
              return total = total + 0.25;
          }
          return null;
      }
  }
  </code></pre>
  
  <p>This is the MainActivity class </p>
  
  <pre><code>public void startClick (View view) {
      showStopButton();
  
      if (stopped) {
          startTime = System.currentTimeMillis() - elapsedTime;
      }
      else {
          startTime = System.currentTimeMillis();
      }
  
      mHandler.removeCallbacks(startTimer);
      mHandler.postDelayed(startTimer, 0);
  }
  </code></pre>
  
  <p>This is the update timer </p>
  
  <pre><code>private void updateTimer (float time) {
      secs = (long)(time/1000);
      mins = (long)((time/1000)/60);
      hrs = (long)(((time/1000)/60)/60);
  
      /* Convert the seconds to String * and format to ensure it has * a leading zero when required */
  
      secs = secs % 60;
      seconds = String.valueOf(secs);
  
      if (secs == 0) {
          seconds = "00";
      }
  
      if (secs &lt; 10 &amp;&amp; secs &gt; 0) {
          seconds = "0" + seconds;
      }
  
      /* Convert the minutes to String and format the String */
  
      mins = mins % 60;
      minutes = String.valueOf(mins);
  
      if (mins == 0) {
          minutes = "00";
      }
  
      if (mins &lt; 10 &amp;&amp; mins &gt; 0) {
          minutes = "0" + minutes;
      }
  
      /* Convert the hours to String and format the String */
  
      hours = String.valueOf(hrs);
  
      if (hrs == 0) {
          hours = "00";
      }
  
      if (hrs &lt; 10 &amp;&amp; hrs &gt; 0) {
          hours = "0" + hours;
      }
  
      ((TextView)findViewById(R.id.timer)).setText(hours + ":" + minutes + ":" + seconds);
  
      Double total = calc.calculateTotal(hrs, mins);
      ((TextView)findViewById(R.id.displayTotal)).setText(total.toString());
  
  }
  </code></pre>
  
  <p>This is the runnable</p>
  
  <pre><code>private Runnable startTimer = new Runnable() {
      public void run() {
          elapsedTime = System.currentTimeMillis() - startTime;
          updateTimer(elapsedTime);
          mHandler.postDelayed(this, 100);
      }
  };
  </code></pre>
  
  <p>When I run the code, it just shows $0.05 but it won't update after 1 minute. </p>
  
  <p>If you can help me solve this or guide me on how to solve this, it would be helpful. Thanks in advance.</p>