[Solved] Using Android Studio, how can I create a value which will increase its value by 1 every time a button is clicked? [closed]


you need to add a button to your .xml file like this :

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Goal"
    android:layout_margin="8dp"
    android:onClick="add1ForTeamA"
    android:id="@+id/Three_Button_B"/>

then if you will notice that the android:onclick has been set to the add1ForTeamA method. Go to the mainActivity.java file and add this method

`public void addOneForTeamA(View view) {
    scoreTeamA = scoreTeamA + 1;
    displayForTeamA(scoreTeamA);
}`
public void displayForTeamA(int score) {
    TextView scoreView = (TextView) findViewById(R.id.Team_A_Score);
    scoreView.setText(String.valueOf(scoreTeamA));

3

solved Using Android Studio, how can I create a value which will increase its value by 1 every time a button is clicked? [closed]