0

Not sure why but the chronometer counter will start as soon as the application starts without me clicking the button. Does anyone see what the issue would be?

package com.example.android.courtcounter;

import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Chronometer;

public class MainActivity extends AppCompatActivity {

    int scoreTeamA = 0;
    int scoreTeamB = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        this.setContentView(R.layout.activity_main);
        setContentView(R.layout.activity_main);

    }
//Display team A score
    public void displayForTeamA(int score){
        TextView scoreView = (TextView) findViewById(R.id.team_a_score);
        scoreView.setText(String.valueOf(score));

    }
//Display team B score
    public void displayForTeamB(int score){
        TextView scoreView = (TextView) findViewById(R.id.team_b_score);
        scoreView.setText(String.valueOf(score));

    }

    //Methods for team A button
    public void threePointsButton(View view){
        int threePoints = 3;
        scoreTeamA = scoreTeamA + threePoints;
        displayForTeamA(scoreTeamA);
    }

    public void twoPointsButton (View view){
        int twoPoints = 2;
        scoreTeamA = scoreTeamA + twoPoints;
        displayForTeamA(scoreTeamA);
    }

    public void freeThrowButton (View view){
        int freeThrow = 1;
        scoreTeamA = scoreTeamA + freeThrow;
        displayForTeamA(scoreTeamA);
    }
//Methods for team B button
    public void threePointsButtonTeamB(View view){
        int threePoints = 3;
        scoreTeamB = scoreTeamB + threePoints;
        displayForTeamB(scoreTeamB);
    }

    public void twoPointsButtonTeamB (View view){
        int twoPoints = 2;
        scoreTeamB = scoreTeamB + twoPoints;
        displayForTeamB(scoreTeamB);
    }

    public void freeThrowButtonTeamB (View view){
        int freeThrow = 1;
        scoreTeamB = scoreTeamB + freeThrow;
        displayForTeamB(scoreTeamB);
    }
//Methods for reset button
    public void resetScores (View view){
        int scoreA = 0;
        int scoreB = 0;
        displayForTeamA(scoreA);
        displayForTeamB(scoreB);
        scoreTeamA = 0;
        scoreTeamB = 0;
    }

//Methods for starting timer
    public void startTime (View view){
        Chronometer myC = (Chronometer) findViewById(R.id.mc);
        myC.start();

    }

    //Methods for stopping timer
    public void stopTime (View view){
        Chronometer myC = (Chronometer) findViewById(R.id.mc);
        myC.setBase(SystemClock.elapsedRealtime());
        myC.stop();

    }

}
3
Contributors
4
Replies
16
Views
1 Year
Discussion Span
Last Post by stultuske
0

That code, I can't find where you created the chronometer. Time to look around the rest of the project files.

0

Hello,

I created the chronometer objectsion in the last two methods.. The methods are buttons in the XML activity_main.

//Methods for starting timer
    public void startTime (View view){
        Chronometer myC = (Chronometer) findViewById(R.id.mc);
        myC.start();
    }
    //Methods for stopping timer
    public void stopTime (View view){
        Chronometer myC = (Chronometer) findViewById(R.id.mc);
        myC.setBase(SystemClock.elapsedRealtime());
        myC.stop();
    }

Is this not creating the chronometer?

0

Sorry but as I read your reply I only see the methods for starting and stopping, but can't find your code for creating the object.

If I was working this, I'd look again at the object creation and any code with its name.

0

also: it's good that you show the startTime and stopTime methods, but as far as we can tell, they're not called anywhere.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.