CS 175/286 - Lecture 4

Cover page image

Cay S. Horstmann

Today's Lecture

Making buttons work

Changing Activities

Activities with Results

Reading Before Next Class

Lab

Making the Buttons Active

  1. Start with the solution to the first homework. Solutions can be found on Github. Run git clone git@github.com:sjsu-fall2013-cs175/solutions.git somewhere outside your cs175 repo
  2. Copy the homework into cs175/lab04:
    cp -R solutions/hw01 cs175/lab04
  3. In Eclipse, select File → New → Project → Android → Android Project from Existing Source select lab04. Then rename the package to edu.sjsu.cs175.lab04 in the Package Explorer. Also rename the package in AndroidManifest.xml and change the app name to Lab 4 in values/strings.xml. (You should make it a habit to do this whenever you make a new lab or homework assignment.)
  4. While we are at it, let's banish tabs from our source files. (Don't know why? Read this.) Go to Window → Preferences and type tabs into the search box in the top left corner. Click on Text Editors and click on Insert spaces for tabs. But wait, that's not all. Now click on Java/Editor/Typing, then on the Formatter link, and on Edit. Change the name from Eclipse (default) to CS185C, and change the Tabs poliy to Spaces only. Click on Apply and Ok. Go to MainActivity.java and select Source → Correct Indentation from the menu. Verify that there are now spaces in the file (by deleting a character in an indented line).
  5. Select File → New → Other → Android → Android Activity and make a ResponseActivity with all the default options.
  6. In the MainActivity, make the first button go to the ResponseActivity when clicked. How did you do that?
  7. What happens when you run the program and click the button?
  8. What happens when you click the Back button in the emulator?
  9. Now make all buttons go to the ResponseActivity. Use a for loop like in the onCreate method.