Problems with the CountDownTimer

Put your problem here if it does not fit any of the other categories.

Problems with the CountDownTimer

Postby nookie1988 » Thu Mar 24, 2011 1:32 pm

Hi guys,

i have a problem with the CountDownTimer. I want to add a point a every third second for 7 minutes. But it doesn't increment the points correctly. At below i will there is my code. At the end i have 134 points, but it's not correct. Can somebody help me?

Code: Select all
package de.testme;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;

public class TestCounter extends Activity {
   
   TextView secondsLeftTextView;
   TextView pointsTextView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        secondsLeftTextView = (TextView) findViewById(R.id.secondsLeft);
        pointsTextView = (TextView) findViewById(R.id.points);
       
        MyCounter counter = new MyCounter(420000,1000);
        counter.start();
    }
   
    private class MyCounter extends CountDownTimer {

      /**
       * counts the points.
       */
      private int points = 1;
      /**
       * count the ticks.
       */
      private int count = 1;
      public MyCounter(final long millisInFuture, long countDownInterval) {
         super(millisInFuture, countDownInterval);
      }

      /**
       * Event which is fired on finished.
       */
      @Override
      public void onFinish() {
      }


      @Override
      public void onTick(final long millisUntilFinished) {
         count++;
         if ((count % 3) == 1) {
            points = (count + 2 ) /3;
            pointsTextView.setText("Points: " + points);
         }
         int secondsLeft = (int) (millisUntilFinished / 1000);         
         secondsLeftTextView.setText("Seconds left: " + (secondsLeft / 60)
               + ":" + (secondsLeft % 60));
      }
   }
}
nookie1988
Junior Developer
Junior Developer
 
Posts: 24
Joined: Mon May 24, 2010 6:53 pm

Top

Re: Problems with the CountDownTimer

Postby nookie1988 » Thu Mar 31, 2011 1:56 pm

Well it works correct on my HTC Desire but not on the emulator.
nookie1988
Junior Developer
Junior Developer
 
Posts: 24
Joined: Mon May 24, 2010 6:53 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests