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();
}
}