Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.scorekeeper;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.TextView;
- public class DisplayPlayersActivity extends AppCompatActivity {
- public int scorePlayer1 = 0;
- public int scorePlayer2 = 9;
- public int scorePlayer3 = 50;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_display_players);
- // Get the intent that started the activity and extract the string
- Intent intent = getIntent();
- String name1 = intent.getStringExtra(MainActivity.PLAYER_NAME1);
- String name2 = intent.getStringExtra(MainActivity.PLAYER_NAME2);
- String name3 = intent.getStringExtra(MainActivity.PLAYER_NAME3);
- // Capture the layout's TextView and set the string as its text
- TextView textView1 = findViewById(R.id.playerName1);
- TextView textView2 = findViewById(R.id.playerName2);
- TextView textView3 = findViewById(R.id.playerName3);
- textView1.setText(name1);
- textView2.setText(name2);
- textView3.setText(name3);
- // Display players scores
- setScorePlayer1(scorePlayer1);
- setScorePlayer2(scorePlayer2);
- setScorePlayer3(scorePlayer3);
- }
- public void setScorePlayer1(int scorePlayer1) {
- TextView textViewScorePlayer1 = findViewById(R.id.totalScorePlayer1);
- String scorePlayer1String = String.format("%03d", scorePlayer1);
- textViewScorePlayer1.setText(scorePlayer1String);
- }
- public void setScorePlayer2(int scorePlayer2) {
- TextView textViewScorePlayer2 = findViewById(R.id.totalScorePlayer2);
- String scorePlayer2String = String.format("%03d", scorePlayer2);
- textViewScorePlayer2.setText(scorePlayer2String);
- }
- public void setScorePlayer3(int scorePlayer3) {
- TextView textViewScorePlayer3 = findViewById(R.id.totalScorePlayer3);
- String scorePlayer3String = String.format("%03d", scorePlayer3);
- textViewScorePlayer3.setText(scorePlayer3String);
- }
- public void incScorePlayer1(View view) {
- this.scorePlayer1++;
- setScorePlayer1(scorePlayer1);
- }
- public void decScorePlayer1(View view) {
- this.scorePlayer1--;
- setScorePlayer1(scorePlayer1);
- }
- public void incScorePlayer2(View view) {
- this.scorePlayer2++;
- setScorePlayer2(scorePlayer2);
- }
- public void decScorePlayer2(View view) {
- this.scorePlayer2--;
- setScorePlayer2(scorePlayer2);
- }
- public void incScorePlayer3(View view) {
- this.scorePlayer3++;
- setScorePlayer3(scorePlayer3);
- }
- public void decScorePlayer3(View view) {
- this.scorePlayer3--;
- setScorePlayer3(scorePlayer3);
- }
- public void clearAllScores (View view) {
- this.scorePlayer1 = 0;
- this.scorePlayer2 = 0;
- this.scorePlayer3 = 0;
- setScorePlayer1(scorePlayer1);
- setScorePlayer2(scorePlayer2);
- setScorePlayer3(scorePlayer3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement