// On create view method called due the Fragment API being extended
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout hazardperception as a view, which can then be manipulated and
    // Returned (due to View nature of Function)
    View v = inflater.inflate(R.layout.hazardperception, container, false);

    // If the screen contains views, clear them
    if (mainLayout != null) mainLayout.removeAllViewsInLayout();

    // Import from arrays.xml / declaring objects to be used
    listOfItems = new ArrayList<HazardPerceptionInstance>();
    videoIDs = getResources().getStringArray(R.array.hazardperception);
    mainLayout = (ListView) v.findViewById(R.id.hazardperception_list);

    // Importing scores from memory
    String scores =
        getActivity()
            .getSharedPreferences(MainActivity.spName, Activity.MODE_PRIVATE)
            .getString("HAZARDPERCEPTIONSCORE", "Error");

    // Error checking the "scores" String
    if (scores.equals("Error")) {
      createBlankScores("HAZARDPERCEPTIONSCORE", "0");
      scoresSplitter =
          getActivity()
              .getSharedPreferences(MainActivity.spName, Activity.MODE_PRIVATE)
              .getString("HAZARDPERCEPTIONSCORE", "Error")
              .split("#");
    } else if (getActivity()
            .getSharedPreferences(MainActivity.spName, Activity.MODE_PRIVATE)
            .getString("HAZARDPERCEPTIONSCORE", "Error")
            .split("#")
            .length
        != getResources().getStringArray(R.array.hazardperception).length) {
      createBlankScores("HAZARDPERCEPTIONSCORE", "0");
      scoresSplitter =
          getActivity()
              .getSharedPreferences(MainActivity.spName, Activity.MODE_PRIVATE)
              .getString("HAZARDPERCEPTIONSCORE", "Error")
              .split("#");

    } else {
      scoresSplitter = scores.split("#");
    }

    // Importing which video's are "viewed" from memory
    String viewed =
        getActivity()
            .getSharedPreferences(MainActivity.spName, Activity.MODE_PRIVATE)
            .getString("HAZARDPERCEPTION", "Error");

    // Error checking the "viewed" String
    if (viewed.equals("Error")) {
      createBlankScores("HAZARDPERCEPTION", "false");
      viewedSplitter =
          getActivity()
              .getSharedPreferences(MainActivity.spName, Activity.MODE_PRIVATE)
              .getString("HAZARDPERCEPTION", "Error")
              .split("#");
    } else if (getActivity()
            .getSharedPreferences(MainActivity.spName, Activity.MODE_PRIVATE)
            .getString("HAZARDPERCEPTION", "Error")
            .split("#")
            .length
        != getResources().getStringArray(R.array.hazardperception).length) {
      createBlankScores("HAZARDPERCEPTION", "false");
      viewedSplitter =
          getActivity()
              .getSharedPreferences(MainActivity.spName, Activity.MODE_PRIVATE)
              .getString("HAZARDPERCEPTION", "Error")
              .split("#");

    } else {
      viewedSplitter = viewed.split("#");
    }

    // Adding an item to the List for every hazard perception video
    for (int i = 0; i < videoIDs.length; i++) {
      listOfItems.add(
          new HazardPerceptionInstance(
              i + 1, Integer.parseInt(scoresSplitter[i]), viewedSplitter[i]));
    }

    // Initialise the adapter in accordance with the list of hazardperception videos, and the layout
    // from which it's based
    hazardAdapter =
        new HazardPerceptionAdapter(getActivity(), R.layout.hazardperceptionview, listOfItems);

    // Setting the layout adapter
    mainLayout.setAdapter(hazardAdapter);
    mainLayout.setDivider(null);

    // Launching the "HazardPerceptionElement" class when an item is clicked.
    mainLayout.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Intent i = new Intent("ACTIVITY_HAZARDPERCEPTIONELEMENT");
            i.putExtra(
                "POSITION",
                position); // Will transfer through "position" to "HazardPerceptionElement"
            i.putExtra("REVIEW", false);
            startActivity(i);
          }
        });

    mainLayout.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(
              AdapterView<?> adapterView, View view, int position, long l) {
            Intent i = new Intent("ACTIVITY_HAZARDPERCEPTIONELEMENT");
            i.putExtra(
                "POSITION",
                position); // Will transfer through "position" to "HazardPerceptionElement"
            i.putExtra("REVIEW", true);
            startActivity(i);
            return true;
          }
        });

    if (!getActivity()
        .getSharedPreferences(MainActivity.spName, Context.MODE_PRIVATE)
        .getBoolean("HAZARD_SEEN", false)) {
      ShowcaseView.ConfigOptions options = new ShowcaseView.ConfigOptions();
      if (MainActivity.showOnce) options.shotType = ShowcaseView.TYPE_ONE_SHOT;
      options.showcaseId = 6;
      ShowcaseView.insertShowcaseView(
          mainLayout,
          getActivity(),
          R.string.tutorial_06_title,
          R.string.tutorial_06_message,
          options);
      getActivity()
          .getSharedPreferences(MainActivity.spName, Context.MODE_PRIVATE)
          .edit()
          .putBoolean("HAZARD_SEEN", true)
          .commit();
    }
    return v;
  }