To Examples

StudentEntryForm Example

Goal:

Directions:

  1. Create an Android project with name StudentEntryForm as an Empty Activity.
  2. Leave the layout as ConstraintLayout.
  3. Set up a second activity with layout file activity_confirmation.xml and Java activity file ConfirmationActivity.java. This new layout has four text views that display the name, grade, gender, and scholarship sent from the first activity.
  4. Drag these widgets from the palette onto the activity_main.xml layout and set constraints for them with ConstraintLayout:
    1. An EditText widget with id=edtxt_name, and hint Enter Name:.
    2. A Spinner container widget with id=spnGrade. Set up this string array in strings.xml:
      <string-array name="grades">
          <item>Grade 9</item>
          <item>Grade 10</item>
          <item>Grade 11/item>
          <item>Grade 12/item>
      </string-array>
      Set
      android.entries="grades"
      
    3. Drag a RadioButtonGroup from the palette onto the layout. Drag two RadioButton widgets from the palette onto the RadioButton group in the Component Tree.  Set the id and text for the first radio button to rad_female and Female.  Set the id and text for the second button to rad_male and Male.
    4. Drag a CheckBox from the palette onto the layout. Set the id to chk_scholarship and the text to Scholarship?
  5. Drag a Button widget from the palette onto the layout.
  6. Drag a TextView widget from the onto the layout. Set the id to txt_output. This text view is temporary to check if the event handler is obtaining the values from the widgets correctly.
  7. Write an onClick event handler for the button that obtains the current settings of the widgets and displays them in the output textview. Use the getSelected method to get the selected item from the spinner; use the isChecked method to see which radio button and checkbox are selected.
  8. Place the ConstraintLayout in a ScrollView.
  9. Run the app to test it. Here are the app activity files so far:
        activity_main.xml   MainActivity.java   strings.xml
  10. Look at the SendMessage Example to remember how to set up and use an Intent to start the second activity, pass the data to it, and display the information on the second activity.
  11. Here are the final versions of the new and modified source code files:
    activity_main.xml   MainActivity.java   strings.xml
    activity_confirmation.xml   ConfirmationActivity.java