Last Updated on December 20, 2020 by AbdurRahman G Official | Md Ghufran Salafi
Add images to the 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.
setImageResource()to change the image that’s displayed in an
- Use control flow statements like
if / elseexpressions or
whenexpressions to handle different cases in your app, for example, showing different images under different circumstances.
- Android Kotlin glossary
ifexpression in Kotlin
whenexpression in Kotlin
Practice on your own
Do the following:
- Add another dice to the app, so that one Roll button gives 2 dice results. How many
ImageViewswill you need in your layout? How will that affect the
Check your work:
Your finished app should run without errors and show the two dice.