Last Updated on December 20, 2020 by AbdurRahman G Official | Md Ghufran Salafi
Create an interactive Dice Roller app:
The solution code for this codelab is in the project and module shown below.
To get the code for this codelab and open it in Android Studio, do the following.
Get the code
- Click on the Solution Code URL. This opens the GitHub page for the project in a browser.
- On the GitHub page for the project, click the Clone or download button, which brings up a Clone dialog.
- In the dialog, click the Download ZIP button to save the project to your computer. Wait for the download to complete.
- Locate the file on your computer (likely in the Downloads folder).
- Double-click the ZIP file to unpack it. This creates a new folder that contains the project files.
Open the project in Android Studio
- Start Android Studio.
- In the Welcome to Android Studio window, click Open an existing Android Studio project.
Note: If Android Studio is already open, instead, select the File > New > Import Project menu option.
- In the Import Project dialog, navigate to where the unzipped project folder is located (likely in your Downloads folder).
- Double-click on that project folder.
- Wait for Android Studio to open the project.
- Click the Run button to build and run the app. Make sure it works as expected.
- Browse the project files in the Project tool window to see how the app was implemented.
- Add a
Buttonin an Android app using the Layout Editor.
- Modify the
MainActivity.ktclass to add interactive behavior to the app.
- Pop up a
Toastmessage as a temporary solution to verify you’re on the right track.
- Set an on-click listener for a
setOnClickListener()to add behavior for when a
- When the app is running, you can update the screen by calling methods on the
Button, or other UI elements in the layout.
- Comment your code to help other people who are reading your code understand what your approach was.
- Reformat your code and clean up your code.
- Vocabulary for Android Basics in Kotlin
- Kotlin Style Guide for Android Developers
Practice on your own
Do the following:
- Add another dice to the app. Clicking on the Roll button should roll 2 dice. The results should be displayed in 2 different
Check your work:
Your finished app should run without errors and show two dice in the app.