To Lecture Notes
Magic8Ball Example
Goal:
- Display a Magic8Ball prediction on the screen. Show a different random
prediction when the screen is clicked.
See this Wikipedia article
for the 20 Magic8 Ball predictions.
Directions:
- Create an Android project named Magic8Ball.
Modifications: Step 1.
- Modify layout to use a linear layout and display one of the Magic8Ball
predictions, for
example, "Ask again later.".
- Here is the resulting layout file:
activity_main.xml
- Test the app.
Modifications: Step 2.
- Modify the app so that it
- contains a Prediction class that returns a random Magic8Ball prediction,
- has a black background color,
- has an onClick event handler so that a new prediction is
displayed when the linear layout is clicked.
- Here are the modified files:
activity_main.xml
Prediction.java
MainActivity.java
Modifications: Step 3.