You are on page 1of 2

Android Fortune Teller Lab 

Directions​: Using your knowledge of arrays and randomness, make an Android app that 
prints random fortunes! 
 
Suggested Components 
● TextView component to display a random fortune 
● ImageButton that the user can press to generate a new fortune. Consider pictures of 
a Magic 8 Ball, crystal ball, fortune teller, etc. (File names should be all lowercase 
letters!) 
● Put images in: Android Project → app → src → main → res → drawable 
 
Helpful Code Excerpts 
Note: these excerpts are not ​exactly​ what you should type -- you will have to think about 
what tweaks you need to make to the code! 
 
Declaring a variable at the top of your code: 
Button button;
Finding a component by its ID and assigning it to a variable: 
button ​=​ (Button) findViewById(R​.​id​.​button);
Creating a click event listener: 
button​.​setOnClickListener(​new​ View.OnClickListener() {
​@Override
​public​ ​void​ ​onClick​(View ​view​) {
​// Display a random fortune!
}
});

Extensions​: 
● Customize the font and color of the fortune text, or the overall color scheme of the 
app. 
● Have the picture change when the user presses the ImageButton (e.g. you could 
have the Magic 8 Ball show the bottom of the 8 Ball, or you could switch to different 
pictures of fortune tellers). 
● Superchallenge:​ Figure out how to make something happen when the phone is 
shaken, and make a new fortune show when the user shakes the phone! 

You might also like