public void saveInspection() {
    String exception = "";
    if (edtException.getText().toString().length() > 0) {
      exception = edtException.getText().toString();
    }
    if (exception.length() > 200) {
      Toast.makeText(
              getApplicationContext(),
              "Exception must be less then 200 character.",
              Toast.LENGTH_LONG)
          .show();
      return;
    }
    String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
    inspection.deleteRelatedPestsRecords();
    if (isCleanInspection) {
      m_inspectionPests = new ArrayList<InspectionPest>();
      inspection.evidence = "";
    }

    inspection.trap_number = trapscan_info.number;
    inspection.trap_type_id = trapscan_info.trap_type_id;
    int bait = 0, trap = 0;
    if (!spnBaitCondition.getSelectedItem().toString().equalsIgnoreCase("Bait Conditions")) {
      bait = BaitConditionsInfo.getIdByName(spnBaitCondition.getSelectedItem().toString());
    }
    if (!spnTrapCondition.getSelectedItem().toString().equalsIgnoreCase("Trap Conditions")) {
      trap = TrapConditionsInfo.getIdByName(spnTrapCondition.getSelectedItem().toString());
    }
    inspection.bait_condition_id = bait;
    inspection.trap_condition_id = trap;
    currentDateTimeString =
        Utils.Instance()
            .getFormatedDate(
                currentDateTimeString, "MMM dd, yyyy hh:mm:ss a", "yyyy-MM-dd hh:mm a");
    inspection.exception = exception;
    inspection.removed = isRemoved;
    inspection.scanned_on = currentDateTimeString;
    try {
      inspection.save();
    } catch (ActiveRecordException e) {
      e.printStackTrace();
    }

    AddTraps(m_inspectionPests, inspection);
    // if (m_list.size() == 1) {
    // if (m_list.get(0).count == 0 && m_list.get(0).pest_type_id == 0) {
    // m_list = new ArrayList<InspectionPest>();
    // AddTraps(m_list, inspection);
    // } else {
    // AddTraps(m_list, inspection);
    // }
    // } else {
    // }
  }
 public void loadMaterial() {
   if (inspection != null) {
     if (inspection.Material_ids != null && inspection.Material_ids.length() > 0) {
       m_inspection_material = new ArrayList<InspectionMaterial>();
       String ids[] = inspection.Material_ids.split(",");
       for (String s : ids) {
         InspectionMaterial.AddMaterial(Utils.ConvertToInt(s));
       }
       m_inspection_material = InspectionMaterial.getAll();
       bindMaterial(m_inspection_material);
     }
   }
 }
  public void bindMaterial(ArrayList<InspectionMaterial> m_arr) {
    ArrayList<MaterialUsage> m_usages = new ArrayList<MaterialUsage>();
    if (m_arr != null && m_arr.size() > 0) {
      for (InspectionMaterial im : m_arr) {
        MaterialUsage usage = MaterialUsage.getMaterialUsageById(im.material_id);
        if (usage != null) {
          m_usages.add(usage);
        }
      }
    }

    MaterialUsageAdapter adapter = new MaterialUsageAdapter(m_usages);
    lstMaterial.setAdapter(adapter);
    Utils.setListViewHeightBasedOnChildren(lstMaterial);
  }