private void editPatients(final Patients patient) {
    final Dialog d = new Dialog(getActivity());
    d.setTitle("Update Entry");
    d.setContentView(R.layout.input_patient_entry);
    TextView header = (TextView) d.findViewById(R.id.header);
    header.setText("Update Contact Entry");
    final TextView first_name = (TextView) d.findViewById(R.id.fname);
    final TextView middle_name = (TextView) d.findViewById(R.id.mi);
    final TextView last_name = (TextView) d.findViewById(R.id.lname);
    final TextView address = (TextView) d.findViewById(R.id.addr);
    final TextView age = (TextView) d.findViewById(R.id.age);
    final TextView medical_history = (TextView) d.findViewById(R.id.med_hist);
    RadioGroup status_group = (RadioGroup) d.findViewById(R.id.status);
    status_group.setVisibility(RadioGroup.GONE);

    Button save = (Button) d.findViewById(R.id.add);
    Button cancel = (Button) d.findViewById(R.id.cancel);

    save.setText("Update");
    first_name.setText(patient.getFname());
    middle_name.setText(patient.getMi());
    last_name.setText(patient.getLname());
    address.setText(patient.getAddr());
    age.setText(Integer.toString(patient.getAge()));
    medical_history.setText(patient.getMed_history());

    save.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            Patients p = patient;
            p.setFname(first_name.getText().toString());
            p.setMi(middle_name.getText().toString());
            p.setLname(last_name.getText().toString());
            p.setAddr(address.getText().toString());
            p.setAge(Integer.parseInt(age.getText().toString()));
            p.setMed_history(medical_history.getText().toString());
            help.update(p, Helper.NORMAL);
            d.cancel();
            Toast.makeText(getActivity(), "Patient Details Updated!", Toast.LENGTH_SHORT).show();
            loadPatientMasterList();
            loadPatientList(patient.getPat_status());
          }
        });
    cancel.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            d.cancel();
          }
        });

    d.show();
  }
  private void editPatients(final Patients patient) {
    final Dialog d = new Dialog(getActivity());
    d.setTitle("Update Entry");
    d.setContentView(R.layout.input_patient_entry);
    TextView header = (TextView) d.findViewById(R.id.header);
    header.setText("Update Contact Entry");
    final TextView first_name = (TextView) d.findViewById(R.id.fname);
    final TextView middle_name = (TextView) d.findViewById(R.id.mi);
    final TextView last_name = (TextView) d.findViewById(R.id.lname);
    final TextView address = (TextView) d.findViewById(R.id.addr);
    final TextView age = (TextView) d.findViewById(R.id.age);
    final TextView medical_history = (TextView) d.findViewById(R.id.med_hist);
    RadioGroup status_group = (RadioGroup) d.findViewById(R.id.status);
    status_group.setVisibility(RadioGroup.GONE);

    save = (Button) d.findViewById(R.id.add);
    Button cancel = (Button) d.findViewById(R.id.cancel);

    save.setEnabled(false);

    save.setText("Update");
    first_name.setText(patient.getFname());
    middle_name.setText(patient.getMi());
    last_name.setText(patient.getLname());
    address.setText(patient.getAddr());
    age.setText(Integer.toString(patient.getAge()));
    medical_history.setText(patient.getMed_history());

    first_name.addTextChangedListener(this);
    middle_name.addTextChangedListener(this);
    last_name.addTextChangedListener(this);
    address.addTextChangedListener(this);
    age.addTextChangedListener(this);
    medical_history.addTextChangedListener(this);

    save.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
            build.setMessage("Are all edits Correct?");
            build.setCancelable(false);
            build.setPositiveButton(
                "Yes",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    Patients p = patient;
                    p.setFname(first_name.getText().toString());
                    p.setMi(middle_name.getText().toString());
                    p.setLname(last_name.getText().toString());
                    p.setAddr(address.getText().toString());
                    p.setAge(Integer.parseInt(age.getText().toString()));
                    p.setMed_history(medical_history.getText().toString());
                    help.update(p, Helper.NORMAL);
                    d.cancel();
                    Toast.makeText(getActivity(), "Patient Details Updated!", Toast.LENGTH_SHORT)
                        .show();
                    loadPatientMasterList();
                    loadPatientList(patient.getPat_status());
                  }
                });
            build.setNegativeButton(
                "No",
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                  }
                });

            AlertDialog alert = build.create();
            alert.show();
          }
        });
    cancel.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            d.cancel();
          }
        });

    d.show();
  }
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Patients patients = (Patients) getListAdapter().getItem(info.position);
    // Toast.makeText(getActivity(), "Full Name of Clicked: "+patients.getId(),
    // Toast.LENGTH_LONG).show();
    // final Patients patients = (Patients) help.getRecord(PATIENTS, id.getText().toString());
    MenuItem edit = menu.add("Edit");
    MenuItem delete = menu.add("Delete");

    if (patients != null && patients.getPat_status() == 1) {
      Log.d("itemCheck", "Patient ID: " + patients.getPatient_id());
      Log.d("itemCheck", "Patient Name: : " + patients.toString());
      help.getPatientSchedule(patients);
      Log.d("itemCheck", "Schedule ID: " + patients.getSchedule_id());
      Log.d("itemCheck", "Location : " + patients.getLocation());
      Log.d("itemCheck", "Hospital Name: " + patients.getHosp_name());
      Log.d("itemCheck", "Hospital Room: " + patients.getHosp_room());
      Log.d("itemCheck", "Time: " + patients.time());
      Log.d("itemCheck", "Request Code: " + patients.getRequestCode());
      Log.d("itemCheck", "Under this Schedule is: Patient Name: " + patients.toString());
      Log.d("itemCheck", "Under this Schedule is: Medical History: " + patients.getMed_history());

      MenuItem update = menu.add("Update Rounds Schedule");
      update.setOnMenuItemClickListener(
          new OnMenuItemClickListener() {

            public boolean onMenuItemClick(MenuItem item) {
              updateRounds(patients);
              return true;
            }
          });
    }

    MenuItem change_status = menu.add("Change Status");

    change_status.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {

          public boolean onMenuItemClick(MenuItem item) {
            changeStatus(patients);
            return true;
          }
        });

    edit.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {

          public boolean onMenuItemClick(MenuItem item) {
            editPatients(patients);
            return true;
          }
        });

    delete.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {
          public boolean onMenuItemClick(MenuItem item) {
            deletePatients(patients);
            return true;
          }
        });
  }