Skip to content

Instantly share code, notes, and snippets.

@mmarquezs
Created April 11, 2017 16:13
Show Gist options
  • Save mmarquezs/91c6c33b2a2e70fd784e52680a492204 to your computer and use it in GitHub Desktop.
Save mmarquezs/91c6c33b2a2e70fd784e52680a492204 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#006600">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
tools:context="com.example.android.scorekeeper.MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Team A"
android:textStyle="bold"
android:textSize="13sp"
android:textAlignment="center"
android:textColor="@android:color/darker_gray"
android:paddingBottom="10dp"
android:paddingTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/teamA_points"
android:textColor="#FFFFFF"
android:text="0"
android:textSize="50sp"
android:paddingBottom="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@android:color/darker_gray"
android:text="Fouls: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/teamA_fouls"
android:textColor="#FFFFFF"
android:text="0"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+1 Point"
android:layout_gravity="center"
android:onClick="increaseTeamAPoints"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+1 Foul"
android:layout_gravity="center"
android:onClick="increaseTeamAFouls"/>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="300dp"
android:background="@android:color/white"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Team B"
android:textAlignment="center"
android:textStyle="bold"
android:textSize="13sp"
android:textColor="@android:color/darker_gray"
android:paddingBottom="10dp"
android:paddingTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/teamB_points"
android:textColor="#FFFFFF"
android:text="0"
android:textSize="50sp"
android:paddingBottom="10dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@android:color/darker_gray"
android:text="Fouls: "/>+
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/teamB_fouls"
android:textColor="#FFFFFF"
android:text="0"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+1 Point"
android:layout_gravity="center"
android:onClick="increaseTeamBPoints"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="+1 Foul"
android:onClick="increaseTeamBFouls"/>
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reset scores"
android:onClick="resetScores"/>
</LinearLayout>
package com.example.android.scorekeeper;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int teamAPoints = 0;
int teamBPoints = 0;
int teamAFouls = 0;
int teamBFouls = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void displayTeamAPoints() {
TextView textView = (TextView) findViewById(R.id.teamA_points);
textView.setText(String.valueOf(teamAPoints));
}
public void displayTeamBPoints() {
TextView textView = (TextView) findViewById(R.id.teamB_points);
textView.setText(String.valueOf(teamBPoints));
}
public void displayTeamAFouls() {
TextView textView = (TextView) findViewById(R.id.teamA_fouls);
textView.setText(String.valueOf(teamAFouls));
}
public void displayTeamBFouls() {
TextView textView = (TextView) findViewById(R.id.teamB_fouls);
textView.setText(String.valueOf(teamBFouls));
}
public void increaseTeamAPoints(View v) {
teamAPoints +=1;
displayTeamAPoints();
}
public void increaseTeamBPoints(View v) {
teamBPoints +=1;
displayTeamBPoints();
}
public void increaseTeamAFouls(View v) {
teamAFouls +=1;
displayTeamAFouls();
}
public void increaseTeamBFouls(View v) {
teamBFouls +=1;
displayTeamBFouls();
}
public void resetScores(View v) {
teamBFouls = 0;
displayTeamBFouls();
teamAFouls = 0;
displayTeamAFouls();
teamBPoints = 0;
displayTeamBPoints();
teamAPoints = 0;
displayTeamAPoints();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment