1

I am using Fragment which is an instance of Fragment and not of DialogFragment

I am displaying form inside this fragment, and one of the field is DateField

I want to have date picker component for that field in Fragment

I did google most of the search result shows how to use DialogFragment to have DatePicker and then use show() method of Fragment

which isn't working in my case because of type mismatch of Fragment and DialogFragment

Any example or idea would be helpful

user602865
  • 261
  • 2
  • 5
  • 10

1 Answers1

10

use this code . I used this datepicker in my fragment ACTIVITY

final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);


        DatePickerDialog dpdFromDate = new DatePickerDialog(getActivity(), mDateSetListener, mYear, mMonth,
                  mDay);
        dpdFromDate.show();

        dpdFromDate.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
               if (which == DialogInterface.BUTTON_NEGATIVE) {
                    //et_to_date.setText("");
                    et_from_date.setText("");
               }
            }
        });
RINK
  • 620
  • 5
  • 15