@Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   ProgramStageRow row = (ProgramStageRow) listView.getItemAtPosition(position);
   if (row instanceof ProgramStageEventRow) {
     ProgramStageEventRow eventRow = (ProgramStageEventRow) row;
     Event event = eventRow.getEvent();
     showDataEntryFragment(event, event.getProgramStageId());
   }
 }
  @Subscribe
  public void onItemClick(OnProgramStageEventClick eventClick) {
    if (eventClick.isHasPressedFailedButton()) {
      switch (eventClick.getStatus()) {
        case ProgramStageEventRow.IS_ERROR:
          {
            Dhis2.getInstance()
                .showErrorDialog(
                    getActivity(),
                    getString(R.string.event_error),
                    eventClick.getErrorMessage(),
                    R.drawable.ic_event_error);
            break;
          }

        case ProgramStageEventRow.IS_OFFLINE:
          {
            Dhis2.getInstance()
                .showErrorDialog(
                    getActivity(),
                    getString(R.string.event_offline),
                    getString(R.string.status_offline_description),
                    R.drawable.ic_offline);
            break;
          }
        case ProgramStageEventRow.IS_ONLINE:
          {
            Dhis2.getInstance()
                .showErrorDialog(
                    getActivity(),
                    getString(R.string.event_sent),
                    getString(R.string.status_sent_description),
                    R.drawable.ic_from_server);
            break;
          }
          //                if (eventClick.getHasFailedButton().getTag() != null) {
          //                    Dhis2.showErrorDialog(getActivity(),
          // getString(R.string.event_status),
          //                            eventClick.getErrorMessage(), (Integer)
          // eventClick.getHasFailedButton().getTag());
          //                } else
          //                    Log.d(CLASS_TAG, "OFFLINE IMAGE BUG");
      }

    } else {
      showDataEntryFragment(eventClick.getEvent(), eventClick.getEvent().getProgramStageId());
    }
  }
  @Override
  public void onClick(View view) {
    switch (view.getId()) {
      case R.id.select_program:
        {
          ProgramDialogFragment fragment =
              ProgramDialogFragment.newInstance(
                  this,
                  mState.getOrgUnitId(),
                  Program.MULTIPLE_EVENTS_WITH_REGISTRATION,
                  Program.SINGLE_EVENT_WITH_REGISTRATION);
          fragment.show(getChildFragmentManager());
          break;
        }

      case R.id.neweventbutton:
        {
          if (mForm.getEnrollment().getStatus().equals(Enrollment.ACTIVE)) {
            ProgramStage programStage = (ProgramStage) view.getTag();
            showDataEntryFragment(null, programStage.getId());
          }
          break;
        }

      case R.id.eventbackground:
        {
          if (mForm.getEnrollment().getStatus().equals(Enrollment.ACTIVE)) {
            Event event = (Event) view.getTag();
            showDataEntryFragment(event, event.getProgramStageId());
          }
        }

      case R.id.complete:
        {
          Dhis2.showConfirmDialog(
              getActivity(),
              getString(R.string.complete),
              getString(R.string.confirm_complete_enrollment),
              getString(R.string.complete),
              getString(R.string.cancel),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  completeEnrollment();
                }
              });
          break;
        }

      case R.id.terminate:
        {
          Dhis2.showConfirmDialog(
              getActivity(),
              getString(R.string.terminate),
              getString(R.string.confirm_terminate_enrollment),
              getString(R.string.terminate),
              getString(R.string.cancel),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  terminateEnrollment();
                }
              });
          break;
        }

      case R.id.followupButton:
        {
          toggleFollowup();
          break;
        }

      case R.id.newenrollmentbutton:
        {
          enroll();
          break;
        }

      case R.id.profile_cardview:
        {
          editTrackedEntityInstanceProfile();
          break;
        }
      case R.id.profile_button:
        {
          editTrackedEntityInstanceProfile();
          break;
        }
    }
  }