Get date from datepicker using dialogfragment
I simple override onDateSet in date picker creation in my class that shows a date picker. See code below:
private OnClickListener onDateClicked() {
return new OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = new DatePickerFragment() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
salePaymentCustomView.setBtDateText("" + day + "/" + month+1 + "/" + year);
}
};
newFragment.show(getActivity().getSupportFragmentManager(), "datePicker");
}
};
}
Constructor fo DatePickerDialog
takes DatePickerDialog.OnDateSetListener
as second parameter, so maybe you should implement that interface in your parent activity EditSessionActivity
(not in DatePickerFragment
) and change this line:
return new DatePickerDialog(getActivity(), this, year, month, day);
into this:
return new DatePickerDialog(getActivity(), (EditSessionActivity)getActivity(), year, month, day);
And then your activity should looks like this:
public class EditSessionActivity extends FragmentActivity implements
DatePickerDialog.OnDateSetListener{
public void onDateSet(DatePicker view, int year, int month, int day) {
//use date in your activity
}
...
}