To Lecture Notes

IT 372 -- Apr 22, 2024

Review Questions

  1. The following code copies the items from an arraylist declared by
    ArrayList<Integer> al = new ArrayList<Integer>( );
    
    into a string:
    String output = "";
    for(Integer n : al) {
        output += n + "\n";
    }
    
    Perform this operation using a StringBuilder object instead. If there are many items in the arraylist, using a stringbuilder object is much faster.
  2. Suppose you have a hashmap collection:
    HashMap<String, Integer> map = 
        new HashMap<String, Integer>( );
    
    How do you add an Integer object to the collection using the key "K123"? How do you retrieve the Integer object? We will use a similar concept when we store information from an activity in a storedInstanceState object.
  3. Add these strings to an ArrayList collection:
    c  java  kotlin  python  
    
    Then use the ArrayList method replaceAll that accepts a lambda function to convert each of the strings to uppercase.
  4. What is an Android drop-down menu called? How do you set one up?
    Answer: It is called a Slider. See the BeerAdvisor and ChineseHoroscope Examples. The Chinese Horiscope Example is in the ArrayAdapters section of the Apr 13 Lecture Notes.
  5. Create an app named TestWidgets. Switch the layout to LinearLayout, with vertical orientation. Add a ScrollView that includes the linear layout. Then place each of these widgets in the linear layout:
    Switch  ToggleButton  Button
    
    When the button is clicked, show the states of the switch and the toggle button.
  6. List the XML attributes that we use to position items in a layout.
  7. What is an Android Toast. How do you display one?
  8. What is an inner class? Give an example of an inner class used to implement an Android event handler.
  9. Create an Android app with four radio buttons with text Freshman, Sophomore, Junior, Senior. Place them in a radio button group. Add a button with text Show Year that shows the selected year using the codes 1, 2, 3, and 4.
  10. How do you restrict the inputs to an EditText widget? For example, how do you set it up so that only numbers can be entered?

Array Adapters

The Chinese Horoscope Example

The Activity Lifecycle

The SendMessage Example