O'Reilly logo

Android User Interface Development by Jason Morris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - developing a simple memory game

Unlike almost all previous example, we'll generate the layout entirely in Java code in this game. The main reason for this is that the content is highly repetitive, each cell containing almost exactly the same widget. We use a TableLayout to create the grid, and display the "cards" in ImageButton widgets. To encapsulate the individual card behavior, we create a MemoryCard inner-class which holds a reference to the ImageButton it controls.

  1. Create a new Java class in the root package of your project, and name it TableLayoutActivity.
  2. Make the new class extend Activity:
    public class TableLayoutActivity extends Activity { Declare and array of all the icon resources to use as card images, there must be ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required