Created
November 19, 2017 08:19
-
-
Save Lzyct/b0041e24cc3bcdbe2caf03ad08102462 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CounterActivity extends AppCompatActivity { | |
| private int nilaiSkor = 0; | |
| private TextView tvCounter; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_counter); // layout counter | |
| tvCounter = findViewById(R.id.tv_counter); | |
| Button btnTambah1 = findViewById(R.id.btn_tambah1); | |
| Button btnTambah2 = findViewById(R.id.btn_tambah2); | |
| Button btnTambah3 = findViewById(R.id.btn_tambah3); | |
| Button btnReset = findViewById(R.id.btn_reset); | |
| btnTambah1.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| nilaiSkor += 1; | |
| ubahSkor(nilaiSkor); | |
| } | |
| }); | |
| btnTambah2.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| nilaiSkor += 2; | |
| ubahSkor(nilaiSkor); | |
| } | |
| }); | |
| btnTambah3.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| nilaiSkor += 3; | |
| ubahSkor(nilaiSkor); | |
| } | |
| }); | |
| btnReset.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| nilaiSkor = 0; | |
| ubahSkor(nilaiSkor); | |
| } | |
| }); | |
| } | |
| private void ubahSkor(int skor) { | |
| tvCounter.setText(String.valueOf(skor)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment