To Lecture Notes

IT 372 -- Apr 15, 2024

Specs for Projects

When you create your project, name it Proj1aSmith (replace 1a by the actual project number and Smith by your last name).

  1. The package that you set when creating your project can be it372 so that the import statement at the top of your Java files will be
    import it372.proj1asmith;
    
  2. Change the title of your app in the strings.xml resource file. Display the title at the top of your app in a TextView widget.
  3. Choose interesting colors and layouts for your projects. We will see how to display an image in an ImageView control today. For Project 1b or Project 2, you can improve your score for creativity by adding an image to your apps.
  4. Extract colors and string constants to the resource files colors.xml and strings.xml.
  5. Both the layout and activity files must have source code comments.
  6. Both the layout and activity files must have headers that look like this:
    In layout file:
    <?xml version="1.0" encoding="utf-8"?>
    <!-- Stan Smith
         Project 1a
         Apr 12, 2021 -->
    
    In activity file:
    // Stan Smith
    // Project 1a
    // Apr 12, 2021
  7. Use Android Studio to create the zipfile of your project.

Practice Exercises

  1. How does the Android app know which layout file to use?
    Ans: It looks in the MainActivity.java file in the onCreate method:
    setContentView(R.layout.activity_main);
    
    This statement tells the activity that activity_main.xml is the layout file.
  2. How do you start an Android app from the virtual device?
    Ans: On the Galaxy Nexus API 22 virtual device, swipe up to view the installed apps. For some versions you click on this icon to show the installed apps:
    Images App.
    Then scroll up or down to find the icon of the app you want to run and click it.
  3. How do you uninstall apps from the Android virtual device? Ans: Click up to view the installed apps, then scroll to find the Settings Icon and click it. Scroll down to find Apps and click it. Scroll down to find Apps & notifications and click it. Click on SEE ALL 18 APPS, scroll to find the app you wish to uninstall, click on the App, click UNINSTALL.
  4. Look at the complete Magic8Ball Example, complete with all 20 possible predictions.
    If you have an Android phone, you may wish to install this app or other apps on your phone. To do this, turn on Developer options using these directions:
         https://developer.android.com/studio/debug/dev-options
    (You really must tap the Build Number option 7 times to enable Developer options). Then connect your phone to your PC with a USB cable and run the app in the Emulator. This will simultaneously install and run the app on your phone.
  5. Look at the section Adding a ScrollView found below in these notes. Then display the following in a linear layout with a scrollview.
    1. Display the numbers from 1 to 1000 in a textview control, one number per line. Add a ScrollView to allow the user to swipe up and down to view all the numbers.
      Answer: Here are the layout and activity files:
           activity_main.xml   MainActivity.java
    2. Start with some Lorem Ipsum text in a textview widget:
      Lorem ipsum dolor sit amet, 
      consectetur adipiscing elit. 
      In nibh lectus, accumsan 
      at ligula sagittis, bibendum 
      suscipit enim.
      
      When the textview widget is clicked, concatenate 100 copies of this paragraph together and display the new repeated text in the textview. Add scrollbars so the user can see the entire textview.
      Answer: Here are the layout and activity files:
           activity_main.xml   MainActivity.java

Android Event Handlers

Using Images

Adding a ScrollView

Project 2

BeerAdvisor Example

Array Adapters