In this video we will build a simple dice roller app. We will display our dice as images in an ImageView. When we click on it, we generate a random number between 1 and 6 and then show the results by setting the appropiate dice image on our ImageView with the setImageResource method.
Source code + dice images:
❗ Subscribe to the channel:
⏯ Watch more tutorials:
⭐ Become a channel member for exclusive tutorials and other perks:
㊙ Help translating the videos:
💚 Support the content:
💬 Join the Discord chat:
🎧 Audiobooks and podcasts for programmers:
👶 How to get started with Android development:
📣 Follow Coding in Flow on social media:
Xem thêm bài viết khác: https://vesovietlott.com/game
Hi, thanks for the tutorial but after i followed the steps, i got two error and they are; Error: Error parsing XML: duplicate attribute, Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:Androidsdkbuild-tools23.0.1aapt.exe'' finished with non-zero exit value 1
please do you know what the problem might be.
I am not getting the design and text option in activity_main
What do i do….???🙄😢
This may be another approach –
int randomInt = random.nextInt(6) + 1;
String diceID = "dice" + randomInt;
int resID = getResources().getIdentifier(diceID, "drawable", getPackageName());
Thanks for the tutorial.
you are awsome
How can I make a button to change the number of dice?
How to contact you sir
Can I control dice of ludo king in online game
Thanks! You helped me to make my app
Hi, it is possible adding a button or an edit text for choosing how many dice you will roll?
Can you add animation while the dice is rolling? Like a 5 second animation before stopping at random number?
why is the 'drawable/dice1' is not showing on mine
How would you print text insted of images ?
How about different types of dice and more than a single dice. Instead of using the dice image, can a number be used? Thanks
Went a little farther and made a D20 dice roller with a background
Hello! Thanks in advance for your fantastic tutorial. I am working on a project for my school, the homework ti do is to create an app and uploaded to the play store. One question, can i upload this app on the store, or is it a problem for you? Im gonna change of course some code ^^
I followed your tutorial and finally finished the demo. I had a problem typing some of the words, but the IDE wouldn't see the word I typed in as an actual type. What is that?
it gives error on mobile as"unfortunately, dice example has stopped" can you please help me to fix it?
Youre so good at explaining everything, thank you!
I didn't replicate this, but what I take with me from it is how simply shown to create an event listener calling function that creates a random number and calls according to the result a picture file and displays it. Nice and simple. Thx.
thank you 🌹
Thanks to you, I was able to complete the project.
how i can show one pic randomly then it will be dont change the pic ???
is it possible to add sound with dice rolling?
please help me to do this.
thats cool…. Nice work bro
happy new year ! your videos is always great ? clear description … you are great ..
Happy 2018 hope its a good year for all of us 🙂
Nice and easy thanks man