Jump to content

    

Проблема с Chronometer

Recommended Posts

jenya7

Создаю Chronometer

Chronometer chronometer;

Создаю Start, Stop, On Tick ивенты

@Override
protected void onCreate(Bundle savedInstanceState)
{
    chronometer = new Chronometer(this);

    btn_start.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            TimerStart();
        }
    });

    btn_stop.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            TimerStop();
        }
    });

    chronometer.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener()
    {
        @Override
        public void onChronometerTick(Chronometer chronometerChanged)
        {
            chronometer = chronometerChanged;
            count++;
            txt_count.setText(String.valueOf(count));

            if (count >= seconds)
            {
                count = 0; 
                //play sound
            }
            
        }
    });
}

И Start, Stop методы

void TimerStart()
{
    seconds = Long.parseLong(txt_seconds.getText().toString());
    count = 0;

    chronometer.setBase(SystemClock.elapsedRealtime());  
    chronometer.start();

    is_running = true;
}

void TimerStop()
{
    chronometer.stop();
    is_running = false;
}

Запускаю chronometer и ставлю точку останова на count++; линии в onChronometerTick. Я попадаю туда только один раз хотя seconds = 100.

Что я упускаю?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.