To Lecture Notes

IT 372 -- May 7, 2025

Review Questions

  1. What are the steps to adding a widget dynamically to a linear layout?
    Ans: (a) Create a new widget by calling the constructor like this:
    Button button = new Button(this);  // this is the context.
    
    (b) Configure the widget, for example:
    button.setText("Push Me");
    
    (c) Add the widget to the layout:
    layout.addView(button);
    
  2. Look up methods from the Canvas class in the Android Developer class docmentation, found at
         developer.android.com.
    Select  More >> Develop >> Android Platform (in Libraries)
    The package name is android.graphics. The Canvas class contains methods for drawing shapes. Here are some of its methods to check out:
    drawCircle  drawOval   drawLine  drawPath
    drawPoint  drawPoints  drawRect   
    
  3. Try out the TouchEvent1 Example.
  4. Write an Android app that draws a circle in a MyView widget when a touch up event occurs. Hint: combine the Drawing0 and TouchEvent1 examples.
  5. Repeatedly draw circles with touch up events. Keep track of the locations of the circles in Point objects stored in an arraylist. Here is the UML diagram for the Point class:
    +---------------------------+
    |          Point            |
    +---------------------------+
    | - x: int                  |
    | - y: int                  |
    +---------------------------+
    | + Point(x : int, y : int) |
    | + getX( ) : int           |
    | + getY( ) : int           |
    | + toString( ) : String    |
    +---------------------------+
    
  6. To the app in Exercise 5, add a reset button to erase all circles and start over.
    Ans: activity_main.xml   Point.java   MyView.java   ActivityMain.java
  7. In Exercise 6, instead of drawing circles, draw a polyline (connected line segments).
  8. Research and test this widget: SeekBar.
    Ans: Here are the layout and activity files:
         activity_main.xml   MainActivity.java
  9. Look at the DrawStar Example.

Project 4

Read from File

Draw Rivers Example

ZooMap App