Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Main Activity for the Roll Dice Game on the SSaurel's Channel
package com.ssaurel.dicer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
public static final Random RANDOM = new Random();
private Button rollDices;
private ImageView imageView1, imageView2;
protected void onCreate(Bundle savedInstanceState) {
rollDices = (Button) findViewById(;
imageView1 = (ImageView) findViewById(;
imageView2 = (ImageView) findViewById(;
rollDices.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
int value1 = randomDiceValue();
int value2 = randomDiceValue();
int res1 = getResources().getIdentifier("dice_" + value1, "drawable", "com.ssaurel.dicer");
int res2 = getResources().getIdentifier("dice_" + value2, "drawable", "com.ssaurel.dicer");
public static int randomDiceValue() {
return RANDOM.nextInt(6) + 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.