// onStop() --> onDestroyView() --> onDestroy() --> onDetach() --> fragment is destroyed
 // The system calls onPause() as the first indication that the user is leaving the fragment
 // (though it does not always mean the fragment is being destroyed). This is usually where you
 // should commit any changes that should be persisted beyond the current user session (because
 // the user might not come back).
 @Override
 public void onPause() {
   if (isTestOutput) {
     System.out.println("onPause activated. sync called");
   }
   if (mListener != null) {
     // use checkedItemPositions array to update selected items in Main Activity
     mListener.syncSelectedTeams(fourthFragListView.getCheckedItemPositions());
   }
   super.onPause();
 }
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    fourthFragListView = (ListView) view.findViewById(R.id.fourth_frag_listview);

    // create a dummy team list - in the production app, this list would be provided by the
    // webserver
    teamList = new ArrayList<>();
    String teamInfo;
    for (int i = 1; i < (numTeams + 1); i++) {
      teamInfo = "Team " + i + "  --  Teamlead" + i;
      teamList.add(teamInfo);
    }

    // instantiate adapter with data list
    teamAdapter = new TeamAdapter(getContext(), teamList);

    // attach adapter to listview
    fourthFragListView.setAdapter(teamAdapter);

    fourthFragListView.setOnItemClickListener(
        new android.widget.AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // handle response in separate method
            clickResponse(position);
          }
        });

    // bring listview's selected-items list up to date with preselected teams so teams
    // whose appointments are all selected show the proper highlighting on startup
    SparseBooleanArray startupSelectedList = mListener.getSBAForSelectedTeams();
    SparseBooleanArray checkedItemPositions = fourthFragListView.getCheckedItemPositions();
    for (int i = 0; i < startupSelectedList.size(); i++) {
      checkedItemPositions.append(
          (startupSelectedList.keyAt(i) - 1), // team i is in listview item i-1
          startupSelectedList.valueAt(i));
    }
  } // end onViewCreated