This is my first project in Android studio. code is a little messy. Im creating a score keeping app for a card game I play with family members.
Im having a problem adding score to main activity from bid activity. how would you store the textview to continue to add to?
Score_activity java code:
public class score_activity extends AppCompatActivity {
// creating an object of the text view
TextView scoreA;
TextView scoreB;
TextView tvA;
TextView tvB;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score);
// assigning the outputs of the user to the object
scoreA = (TextView) findViewById(R.id.scoreA);
scoreB = (TextView) findViewById(R.id.scoreB);
tvA = (TextView) findViewById(R.id.nameA);
tvB = (TextView) findViewById(R.id.nameB);
Bundle bundle = getIntent().getExtras();
String text1 = bundle.getString("Team A");
String text2 = bundle.getString("Team B");
String text3 = getIntent().getStringExtra("ScoreA");
String text4 = getIntent().getStringExtra("ScoreB");
// setting the fetched data to the corresponding text views
tvA.setText(text1);
tvB.setText(text2);
scoreA.setText(text3);
scoreB.setText(text4);
// this method is the logic that increases the value in the text
view by one on every click for team A
}
Bid Activity code
public void scoreTotal(View view) {
String nameA = tvTeamA.getText().toString();
String nameB = tvTeamB.getText().toString();
int bida = Integer.parseInt(bidA.getText().toString());
int tricksTotalA =
Integer.parseInt(tricksA.getText().toString());
int totalB = 25 - tricksTotalA;
int totalScoreBA = mentionteamA + tricksTotalA;
int totalScoreBB = mentionteamB + totalB;
if (bida > totalScoreBA) {
scoreA2 = (bida * -1);
String scoreBoardA = String.valueOf(scoreA2);
String scoreBoardB = String.valueOf(totalScoreBB);
Intent i = new Intent(bid_activity.this,
score_activity.class);
i.putExtra("Team A", nameA);
i.putExtra("Team B", nameB);
i.putExtra("ScoreA", scoreBoardA);
i.putExtra("ScoreB", scoreBoardB);
// starting the activity
startActivity(i);
}
if (bida <= totalScoreBA) {
scoreA2 = totalScoreBA;
String scoreBoardA = String.valueOf(scoreA2);
String scoreBoardB = String.valueOf(totalScoreBB);
Intent i = new Intent(bid_activity.this,
score_activity.class);
i.putExtra("Team A", nameA);
i.putExtra("Team B", nameB);
i.putExtra("ScoreA", scoreBoardA);
i.putExtra("ScoreB", scoreBoardB);
// starting the activity
startActivity(i);
}
if (tricksTotalA == 25) {
scoreA2 = totalScoreBA;
int displayB = 0;
String scoreBoardA = String.valueOf(scoreA2);
String scoreBoardB = String.valueOf(displayB);
Intent i = new Intent(bid_activity.this,
score_activity.class);
i.putExtra("Team A", nameA);
i.putExtra("Team B", nameB);
i.putExtra("ScoreA", scoreBoardA);
i.putExtra("ScoreB", scoreBoardB);
// starting the activity
startActivity(i);
}