Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.Kalkulator;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.ImageView;
- import java.util.Random;
- public class MainActivity3 extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
- ImageView dice;
- Random random = new Random();
- void baciKocku(){
- int i = random.nextInt(6) + 1;
- switch(i){
- case 1:
- dice.setImageResource(R.drawable.one);
- break;
- case 2:
- dice.setImageResource(R.drawable.two);
- break;
- case 3:
- dice.setImageResource(R.drawable.three);
- break;
- case 4:
- dice.setImageResource(R.drawable.four);
- break;
- case 5:
- dice.setImageResource(R.drawable.five);
- break;
- case 6:
- dice.setImageResource(R.drawable.six);
- break;
- // "R.drawable." + naziv slike kocke od vrijednosti 1-6
- // Izbrisati ^^
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- dice = findViewById(R.id.kocka);
- dice.setOnClickListener(view -> {
- baciKocku();
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement