DatePicker shows same date

I am develpoing a completely different app and it uses some of the functionality of DatePicker Fragment.
I have an edittext and a button.On click of button i am showing DatePicker and when one of the date is selected ,i am showing that date in edittext.When i again press the DatePicker it shows current date which i dont want.I want it to show the date which is set in EditText.

public class DatePickerFragment extends DialogFragment {

private static final String ARGDATE=“mydate”;
private DatePicker datePicker;
public static final String EXTRA_DATE=“extradate”;

public Dialog onCreateDialog(Bundle savedInstanceState) {
Date date = (Date) getArguments().getSerializable(ARGDATE);
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);

View view= LayoutInflater.from(getActivity()).inflate(R.layout.dialog_date,null);
AlertDialog builder=new AlertDialog.Builder(getActivity())
        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                int year=datePicker.getYear();
                int month=datePicker.getMonth();
                int day=datePicker.getDayOfMonth();
                Date date=new GregorianCalendar(year,month,day).getTime();
        }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                if (dialog != null) {

datePicker = (DatePicker) view.findViewById(;
datePicker.init(year, month, day, null);

return builder;


public static DatePickerFragment newInstance(Date date){
DatePickerFragment datePickerFragment=new DatePickerFragment();
Bundle bundle=new Bundle();
return datePickerFragment;

//To send data to CrimeFragment which date you choose in DatePicker
private void sendDate(int resultCode,Date date){

Intent intent=new Intent();


public class EditorFragment extends Fragment{
private static final String DateDialog = “datedialog”;
private static final int REQUEST_DATE = 0;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_editor,container,false);

final Date date=new Date();
String PATTERN = “EEEE,dd-MMMM yyyy”;
SimpleDateFormat dateFormat = new SimpleDateFormat(PATTERN);
final String date1 = dateFormat.format(date.getTime());
CalendarImageButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

                FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
                //Date date2 = (Date)DueDate.getText();
                DatePickerFragment datePickerFragment = DatePickerFragment.newInstance(date);
                //To get result from DatePickerFragemnt
                datePickerFragment.setTargetFragment(EditorFragment.this, REQUEST_DATE);
      , DateDialog);


        return view;

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_DATE && resultCode == Activity.RESULT_OK) {
            Date date = (Date) data

            String PATTERN = "EEEE,dd-MMMM yyyy";
            SimpleDateFormat dateFormat = new SimpleDateFormat(PATTERN);
            String date1 = dateFormat.format(date.getTime());

I am not using any POJO class so i cant use getDate and setDate

Hey, it works.
you can do that

Calendar calendar = new GregorianCalendar();