To Lecture Notes

IT 372 -- May 11, 2026

Review Exercises

Today and in future class notes, Jetpack Compose will be referred to as JPC and JPC Examples will be referred to as JPCEx.

  1. Which JPC elements correspond to these View widgets?
        TextView  Button  ImageView  EditText  LinearLayout
    Answer: the corresponding JPC elements are
           Text  Button  Image  TextField  Column (or Row)
  2. What is needed to create a JPC composable function?
    Answer: the function needs the @Composable annotation at its top.
  3. How do you set up the Android Studio preview for your JPC layout?
    Answer: use the annotation @Preview(showBackground = true) at its top.
  4. How does Modifier work? Technically, Modifier is an interface, but we can think of it as a class with static functions.
    Answer: To be posted soon.
  5. JPC composables do not remember their own states. What is done to remedy this?
    Answer: use a MutableState object like this:
    var checkBoxState = remember { mutableStateOf(true) }
    
  6. How can you round a Kotlin Double value to 3 digits after the decimal point.
    Answer: use the static String method format, which is the same in Java:
    val PI = 3.14159265
    var s = String.format("%.3f", PI)
    println(s)
    // Output: 3.142
    

JetPack Compose Examples

Look at JPCEx 5, 7, 8, 9, 10, 11, 12, 13, 14.

Practice Problems

  1. Modify the JPCEx 1, TextWithTitle to define a CustomText composable with parameters text, backgroundColor, and textColor to display the title and notable item instead of using two Text elements
  2. Place strings and colors in Problem 1 in the resource files strings.xml and colors.xml.
  3. Look at Views Example. Here are the source code files:
          activity_main.xml  MainActivity.java  theraven.txt
    Create a new raw folder in the res/values folder, then copy the raven.txt file to that folder. The  JPC version of this example is JPCEx 15.