Dice Roller (With Code and Image Files) – Android Studio Tutorial



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:

Facebook:

Instagram:

Twitter:

Blog:

Nguồn: https://vesovietlott.com

Xem thêm bài viết khác: https://vesovietlott.com/game

Views:
114
Article Tags:
Article Categories:
Game

Comments

  • 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.

    Margaret Neeley July 2, 2020 6:22 pm Reply
  • I am not getting the design and text option in activity_main
    What do i do….???🙄😢

    Pratham Maithia July 2, 2020 6:22 pm Reply
  • This may be another approach –

    int randomInt = random.nextInt(6) + 1;

    String diceID = "dice" + randomInt;
    int resID = getResources().getIdentifier(diceID, "drawable", getPackageName());

    imageViewDice.setImageResource(resID);

    Thanks for the tutorial.

    Kaushik Sharma July 2, 2020 6:22 pm Reply
  • you are awsome

    Ali Abdaon July 2, 2020 6:22 pm Reply
  • How can I make a button to change the number of dice?

    Mr.Raj Daddy July 2, 2020 6:22 pm Reply
  • How to contact you sir

    Shailesh Upadhyay July 2, 2020 6:22 pm Reply
  • Hi sir,
    Can I control dice of ludo king in online game

    Shailesh Upadhyay July 2, 2020 6:22 pm Reply
  • thanks amazing

    omer ismail July 2, 2020 6:22 pm Reply
  • Thanks! You helped me to make my app
    https://play.google.com/store/apps/details?id=com.randomnumbers.dice
    Awesome video

    Doctor Pizza July 2, 2020 6:22 pm Reply
  • Hi, it is possible adding a button or an edit text for choosing how many dice you will roll?

    Luigi July 2, 2020 6:22 pm Reply
  • Can you add animation while the dice is rolling? Like a 5 second animation before stopping at random number?

    John Laurus July 2, 2020 6:22 pm Reply
  • why is the 'drawable/dice1' is not showing on mine

    Tine De Leon July 2, 2020 6:22 pm Reply
  • How would you print text insted of images ?

    domagoj peric July 2, 2020 6:22 pm Reply
  • How about different types of dice and more than a single dice. Instead of using the dice image, can a number be used? Thanks

    Mike Atencio July 2, 2020 6:22 pm Reply
  • Went a little farther and made a D20 dice roller with a background

    OrokuSaki1986 July 2, 2020 6:22 pm Reply
  • 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 ^^

    Alessio July 2, 2020 6:22 pm Reply
  • 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?

    John Zyski July 2, 2020 6:22 pm Reply
  • it gives error on mobile as"unfortunately, dice example has stopped" can you please help me to fix it?

    Benginur Hajjaj July 2, 2020 6:22 pm Reply
  • Youre so good at explaining everything, thank you!

    Samuel Lowery July 2, 2020 6:22 pm Reply
  • 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.

    Wolfgang Benfattoum July 2, 2020 6:22 pm Reply
  • thank you 🌹

    Ibrahim Odeh July 2, 2020 6:22 pm Reply
  • Thanks to you, I was able to complete the project.

    최시찬 July 2, 2020 6:22 pm Reply
  • how i can show one pic randomly then it will be dont change the pic ???

    L.E. D July 2, 2020 6:22 pm Reply
  • is it possible to add sound with dice rolling?
    please help me to do this.

    monika masud July 2, 2020 6:22 pm Reply
  • thats cool…. Nice work bro

    Android Learners July 2, 2020 6:22 pm Reply
  • happy new year ! your videos is always great ? clear description … you are great ..

    AKASH KUMAR DAS July 2, 2020 6:22 pm Reply
  • Happy 2018 hope its a good year for all of us 🙂

    eyad July 2, 2020 6:22 pm Reply
  • Nice and easy thanks man

    eyad July 2, 2020 6:22 pm Reply

Leave a Reply

Your email address will not be published. Required fields are marked *