Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sturdustgeorgiana/3a74531ea8a8c4d72bcebc7970b338d7 to your computer and use it in GitHub Desktop.
Save sturdustgeorgiana/3a74531ea8a8c4d72bcebc7970b338d7 to your computer and use it in GitHub Desktop.
My first gist thanks to Udacity`s course Android for Beginners
package com.sistahwork.baseball;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
public class ThisActivity extends AppCompatActivity {
int scoreTeamA = 0;
int scoreTeamB = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Increase the score for Team A by 1 point.
*/
public void addOneForTeamA(View v) {
scoreTeamA = scoreTeamA + 1;
displayForTeamA(scoreTeamA);
}
/**
* Increase the score for Team A by 2 points.
*/
public void addTwoForTeamA(View v) {
scoreTeamA = scoreTeamA +2;
displayForTeamA(scoreTeamA);
}
/**
* Increase the score for Team A by 3 points.
*/
public void addThreeForTeamA(View v) {
scoreTeamA=scoreTeamA+3;
displayForTeamA(scoreTeamA);
}
/**
* Increase the score for Team B by 1 point.
*/
public void addOneForTeamB(View v) {
scoreTeamB = scoreTeamB + 1;
displayForTeamB(scoreTeamB);
}
/**
* Increase the score for Team B by 2 point.
*/
public void addTwoForTeamB (View v) {
scoreTeamB = scoreTeamB + 2;
displayForTeamB(scoreTeamB);
}
/**
* Increase the score for Team B by 3 points.
*/
public void addThreeForTeamB(View v){
scoreTeamB = scoreTeamB + 3;
displayForTeamB(scoreTeamB);
}
/**
* Displays the given score for Team A.
*/
public void displayForTeamA(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_a_score);
scoreView.setText(String.valueOf(score));
}
/**
* Displays the given score for Team B.
*/
public void displayForTeamB(int score) {
TextView scoreView = (TextView) findViewById(R.id.team_b_score);
scoreView.setText(String.valueOf(score));
}
public void resetScore (View v){
scoreTeamB = 0;
scoreTeamA = 0;
displayForTeamB(scoreTeamB);
displayForTeamA(scoreTeamA);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment