Presentation is loading. Please wait.

Presentation is loading. Please wait.

Field Trip #30 A Memory Game By Keith Lynn. View A View is the basic building block of an app Some Views hold other views An example of this is GridLayout.

Similar presentations


Presentation on theme: "Field Trip #30 A Memory Game By Keith Lynn. View A View is the basic building block of an app Some Views hold other views An example of this is GridLayout."— Presentation transcript:

1 Field Trip #30 A Memory Game By Keith Lynn

2 View A View is the basic building block of an app Some Views hold other views An example of this is GridLayout A GridLayout puts components in rows and columns

3 ImageView A View which hold images is ImageView In order to add an image to an app, we drag it to a drawable folder This generates an id in R.java We can create a Drawable using the id with the method getResources().getDrawable(id) We can put the Drawable in the ImageView with the method setImageDrawable

4 Image When we draw the image into a drawable folder, it generates an id in R.java It creates a nested class called drawable We access the id with R.drawable.id The id is the name of the file

5 Sound We can add sounds to an app by creating a raw folder under res When we drag a sound file into the raw folder, it generates an id in a nested class in R We can play the sound by creating a MediaPlayer We can play the sound with the method start

6 Events We can detect and act on events In this app, we use an OnClickListener OnClickListener is an inner class of View It contains the method onClick(View) If the onClickListener is registered on a button, then when we click the button, onClick is called

7 Handlers A Handler allows you to send and process messages and Runnable objects associated with a Thread We use a handler to delay an activity for a time To create a Handler, we create a Runnable object

8 The Game In order to play the game, we create two arrays The first array contains 16 ids of images, and the second array contains 16 ids of corresponding sounds For each button, we use its tag A tag is a String associated with a View In the tag we put the id of the image or sound followed by a semicolon followed by the index in the array

9 The game, cont'd When a button is clicked, a variable called firstButton points to it. The corresponding sound plays When a second button is clicked, we compare the first part of their tags If they are the same, then the images match If they match, then the buttons disappear The game is over when all buttons disappear


Download ppt "Field Trip #30 A Memory Game By Keith Lynn. View A View is the basic building block of an app Some Views hold other views An example of this is GridLayout."

Similar presentations


Ads by Google