Stopwatch Android

You must Login before you can answer or comment on any questions.

Stopwatch App is for Android. I am using Titanium Studio and JavaScript. I am trying to make my "Stop" button to perform another action. I want it to resume the time. I am also trying to make my "Lap" button work. Why doesn't my event listener fire for both the "Stop" and "Lap" buttons? I know this is very basic code, but programming is not my strongest point..."button03" is the STOP button, and "button04" is the LAP button. Any help will be appreciated. I have attached parts of my code below that is relevant to my question. Thanks.

var _startStopwatch = function() {
    timerlabel.value = '00:00:00.0';
 
 
var startTime = new Date();
 
var _updateTimer = function updateTimer() {
    var UNIT_HOUR = 60 * 60 * 1000;
    var UNIT_MINUTE = 60 * 1000;
    var UNIT_SEC = 1000;
    var now = new Date();
    var diff = now.getTime() - startTime.getTime();
    var hour = Math.floor(diff / UNIT_HOUR);
    var minute = Math.floor((diff - hour * UNIT_HOUR) / UNIT_MINUTE);
    var sec = Math.floor((diff - hour * UNIT_HOUR - minute * UNIT_MINUTE) / UNIT_SEC);
    var msec = Math.floor(diff % UNIT_SEC);
    timerlabel.text = ('0' + hour).slice(-2) + ':' + ('0' + minute).slice(-2) + ':' + ('0' + sec).slice(-2) + '.' + ('00' + msec).slice(-1);
    };
 
    intervalid = setInterval(_updateTimer, 3);
    button03.title = 'STOP';
    };
 
    var _stopStopwatch = function() {
        clearInterval(intervalid);
    };
 
    var started = false;
    var intervalid = null;
    var resume = true;
 
button03.addEventListener("click", function(e){
    if (started) {    
        _stopStopwatch();
        started = false;
    } else {
        resume = true;  
    }
});
 
//NOT FUNCTIONING.
button04.addEventListener("click", function(e) {
    if (button01 == null | button03 == null) {
        return 'Undefined';
    } else {
        return(button03 - button01) / 1000;
    }
});

— asked 7 months ago by Bhavik Raniga
3 Comments
  • I still fail to see what is your problem exactly...

    — commented 7 months ago by Christian Brousseau

  • The problem is that I can't seem to get my event listener to fire for both the Stop and Lap buttons. The Stop button stops the time, but I also want the Stop button to resume the time and I want the Lap button to lap times every time it is pressed.

    — commented 7 months ago by Bhavik Raniga

  • I've posted a similar thing dude, you should've told me haha

    — commented 7 months ago by Bruce Ruffalo

2 Answers

sorry wrong person.

— answered 7 months ago by james rowland
answer permalink
1 Comment
  • WTF Rowland?? Neither of these are answers. Im surprised that you only got 2 down votes. Please use the comment system when you don't have an actual answer to post.

    — commented 7 months ago by Anthony Decena

Your Answer

Think you can help? Login to answer this question!