To Lecture Notes

IT 372 -- Apr 29, 2024

Review Questions

  1. Where is this message displayed?
    Log.i("001", "This is a test message?");
    
  2. How do you add a second activity to an app?
  3. Look at the details of the SendMessage Example.
  4. Create an Android app named Greeter with three activities named MainActivity, Greeter2Activity, and Greeter3Activity. MainActivity displays the greeting
    Hello, how are you?
    Click for next activity.
    
    Greeter2Activity displays the message
    I'm fine, thank you, and you?
    Click for next activity.
    
    Greeter3Activity displays the message
    I'm fine too, thanks.
    Click for main activity.
    
    Implement the onClick event handlers with lambda functions.
    Ans: Here are the source code files:
    activity_main.xml   MainActivity.java
    activity_greeter2.xml  Greeter2Activity.java
    activity_greeter3.xml  Greeter3Activity.java

Practice with ConstraintLayout

StudentEntryForm Example

Practice Problem

  1. Set up a ConstraintLayout form to input grocery item data with these fields: description (String), code (int), and price (double). When the Submit Grocery Item button is clicked, contatenate the information to the String variable groceryItems that is displayed on a new activity. Ans:
         activity_main.xml  MainActivity.java
         activity_display_items.xml  DisplayItemsActivity.java
    When the virtual device is rotated, save the groceryItems variable in a Bundle object so that this variable can be restored when the activity is recreated after the activity is destroyed due to device rotation.
    Ans: Main activity after adding onSaveInstanceState method and statements in onCreate to restore bundle.
         MainActivity.java

The Android Studio IDE

Practice Problem

  1. Create an app named ShowSuit. Add a radiobutton group with four radio buttons and an ImageView widget to the ConstraintLayout. Set the text for the radio buttons to Club, Diamond, Heart, and Spade. Set up an onCheckedChangListener event handler that changes the image of the imageview to club.png, diamond.png, heart.png, or spade.png, depending on the radiobutton that is clicked. Here is a zipfile of the suit images.  Use an anonymous inner class to set up the event handler.
    Ans: Copy the suit images files into the res/drawable folder. Here are the layout and activity files. Also, see the ShowSuit Example for a different implementation of this problem.

The weight Attribute

Android Platform