Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to make more idiomatic #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions DiceRoller/app/src/main/java/com/example/diceroller/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ class MainActivity : AppCompatActivity() {

// Find the ImageView in the layout
val diceImage: ImageView = findViewById(R.id.imageView)

// Update the ImageView with the correct drawable resource ID
diceImage.setImageResource(

// Determine which drawable resource ID to use based on the dice roll
val drawableResource = when (diceRoll) {
1 -> R.drawable.dice_1
2 -> R.drawable.dice_2
3 -> R.drawable.dice_3
4 -> R.drawable.dice_4
5 -> R.drawable.dice_5
else -> R.drawable.dice_6
}
// Determine which drawable resource ID to use based on the dice roll
when (diceRoll) {
1 -> R.drawable.dice_1
2 -> R.drawable.dice_2
3 -> R.drawable.dice_3
4 -> R.drawable.dice_4
5 -> R.drawable.dice_5
else -> R.drawable.dice_6
}

// Update the ImageView with the correct drawable resource ID
diceImage.setImageResource(drawableResource)
)

// Update the content description
diceImage.contentDescription = diceRoll.toString()
Expand Down