All documentation & example seems to be related to "How to get the date selected from the datepicker dialog back in the activity". And almost all of them sets the current date as default date in the datepicker dialog. However how do I pass a specific date so that when the datepicker opens, it shows that date & not current date?
The problem I'm facing is, when the user clicks a button and the datepicker diaglog opens for the first time, it shows the current time.
The user changes the value and clicks done.
When the button is clicked again, the datepicker dialog is opened. However instead of the changed date, the value is still the default date!!
Code:
public class DatePickerFragment extends SherlockDialogFragment
implements android.app.DatePickerDialog.OnDateSetListener{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
//TODO Use current date is date null, else show currently displayed date
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
((NewTransactionActivity) getActivity()).updateDate(year, monthOfYear, dayOfMonth);
}
}
The above code is the reason for the datepicker always showing up with default date. However how do I pass the date value to this fragment?
This is code from the activity:
public void showDatePickerDialog(View v) {
Bundle currentDate = new Bundle();
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
}