John John - 1 month ago 26
Android Question

Set DatePickerDialog title permanently

I have a problem when I'm trying to set DatePickerDialog title permanently.

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

public Dialog onCreateDialog(Bundle savedInstanceState) {

// 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
DatePickerDialog dpd = new DatePickerDialog(getActivity(), this, year, month, day);
dpd.setTitle("set date");
return dpd;

public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user

public class MainActivity extends FragmentActivity {

public void onCreate(Bundle savedInstanceState) {

Button btn = (Button) findViewById(;

btn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
DialogFragment newFragment = new DatePickerFragment();, "datePicker");


When I click button DatePickerDialog shows and dialog title is "set date" but when I change date, title contains selected date rather than "set date". How can I set this dialog title permanently?

Tested on API 8-10.

Thank you in advance and sorry for my English. Patrick


How about extending DatePickerDialog and adding a setPermanentTitle method to store a permanent title that will be forced when date gets changed ?

public class MyDatePickerDialog extends DatePickerDialog {

    private CharSequence title;

    public MyDatePickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) {
        super(context, callBack, year, monthOfYear, dayOfMonth);

    public void setPermanentTitle(CharSequence title) {
        this.title = title;

    public void onDateChanged(DatePicker view, int year, int month, int day) {
        super.onDateChanged(view, year, month, day);

And then use the new setPermanentTitle method:

    MyDatePickerDialog dpd = new MyDatePickerDialog(this, null, 2012, 10, 10);
    dpd.setPermanentTitle("set date");