To Lecture Notes

IT 372 -- Apr 8, 2019

Review Questions

  1. What is Hungarian notation?
    Ans: It is when the name of a widget (Android name for a control) has a 3 or 4 letter prefix that indicates the widget type, for example txt for TextView, btn for button, spnr for Spinner. Usually hungarian notation is used for Java variable names.
  2. Why should literal strings not be displayed on an app layout? What is the alternative?
    Ans: literal strings make the app code less flexible. A better alternative is to define strings in the strings.xml resource file and reference them in the Java source code.
  3. How is a string defined in the strings.xml resource file? Ans:
    <string name="greeting">Hello, World!</string>
    
  4. How is a string accessed from a resource file? Ans:
    From a layout file:
    android:text="@string/greeting"
    
    From a Java activity file:
    String s = getString(R.string.greeting);
    
  5. List some plausable attributes, methods, and events for a BasketballPlayer class. Attribute is another name for instance variable. Ans:

    Attributes Methods Events
    height shoot Hear ref's whistle
    weight dribble Hear buzzer
    name run See other player become open
    jerseyNumber pass Player sees that he is open
    isRookie stop See incoming ball

  6. List some plausable attributes, methods, and events for a TextView class. Ans:

    Attributes Methods Events
    id move click
    text resize longClick
    textColor setFocus swipe
    backgroundColor   gotFocus
    margin   lostFocus

  7. What is an event handler? How do you set one up?
    Ans: an event handler is a method that executes when an event occurs. Suppose that the event handler in the Java Activity file is defined like this:
    public void myEventHandler(View view) {
        // Body of event handler goes here.
    }
    
    Then in the layout file, the event handler is connected to a buttons click event like this:
    androidandroid:onClick="myEventHandler"
    
  8. In an event handler, how can you access and change the text that is displayed in a TextView control?. Ans:
    // Access the text:
    String s = txtValue.getText( );
    
    // Change the text:
    txtValue.setText(s);
    

Android Platform

XML Primer

Measurement Units

Android Event Handlers

Projects 1a and 1b

  1. Questions about Project 1a and Project 1b.

Project 2