Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.mycounterapplication;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- // 1 - define variables
- private TextView tvMyCounter;
- private Button btnAdd, btnMinus, btnRestart, btnQuit;
- private int count = 0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // 2 - set layout connection to local variables
- tvMyCounter = findViewById(R.id.tvCounter);
- btnAdd = findViewById(R.id.btnAdd);
- btnMinus = findViewById(R.id.btnMinus);
- btnRestart = findViewById(R.id.btnRestart);
- btnQuit = findViewById(R.id.btnQuit);
- // 3 - test
- tvMyCounter.setText("0");
- }
- public void exit(View view) {
- finish();
- }
- public void add(View view) {
- count++;
- tvMyCounter.setText(count + "");
- }
- public void minus(View view) {
- if (count > 0) {
- count--;
- tvMyCounter.setText(count + "");
- }
- }
- public void restart(View view) {
- count = 0;
- tvMyCounter.setText("0");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement