Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8354485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:33:46+00:00 2026-06-09T09:33:46+00:00

I’ve a problem with a DatePickerDialog following steps from Android Tutorial. Linking a TextView

  • 0

I’ve a problem with a DatePickerDialog following steps from Android Tutorial.

Linking a TextView to launch a DatePickerDialog when gets focused as you can see below:

EditText fNac = (EditText)findViewById(R.id.regFecha);
            fNac.setonfocusChangeListener(new View.onfocusChangeListener(){

                    @Override
                    public void onfocusChange(View v, boolean hasFocus) {
                            // TODO Auto-generated method stub
                            // Desde aquí lanzamos el datepicker
                            if (hasFocus){
                                    DialogFragment newFragment = new DatePickerFragment();
                                    newFragment.show(getSupportFragmentManager() , "datePicker");
                            }
                    }

Works fine, the DatePickerDialog is launched. I instance a new DatePickerFragment class that is created in this way:

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.widget.DatePicker;

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

    private DatePickerDialog mDatePickerDialog;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState){
            // Usamos la fecha actual como primera fecha a mostrar
            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);

            // Devolvemos la instancia de un Dialog con la fecha actual
            mDatePickerDialog = new DatePickerDialog(getActivity(),this,year,month,day);
            return mDatePickerDialog;
    }

    @Override
    public void onDateSet(DatePicker view, int year, int month, int day) {
            // TODO Auto-generated method stub
            Log.v("LOG_CAT","OK");
    }

    public void onDateChanged(DatePicker view, int year, int monthOfYear,
                    int dayOfMonth) {
            // TODO Auto-generated method stub
            Log.v("LOG_CAT", "Ok2");
    }

}

And here is the problem. I want to change Dialog’s title using onDateChanged method, but it’s never called. I tried to create a onDateChangedListener but DatePickerDialog doesn’t have one.

How can i do this?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:33:47+00:00Added an answer on June 9, 2026 at 9:33 am

    Simply extend the DatePickerDialog class and override onDateChanged like below. I included a new constructor that accepts a Calendar object and sets the year, month and day itself, saving you the unnecessary typing. (I don’t understand why this isn’t an option already.) Anyway here is how to use the class and the shorter constructor:

    public class DatePickerFragment extends DialogFragment implements OnDateSetListener {
        public class MyDatePickerDialog extends DatePickerDialog {
            private Calendar calendar;
            private final String format = "EEEE, MMMM dd, yyyy";
    
            // Regular constructor
            public MyDatePickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) {
                super(context, callBack, year, monthOfYear, dayOfMonth);
                calendar = Calendar.getInstance();
            }
    
            // Short constructor
            public MyDatePickerDialog(Context context, OnDateSetListener callBack, Calendar calendar) {
                super(context, callBack, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
                this.calendar = calendar;
            }
    
            @Override
            public void onDateChanged(DatePicker view, int year, int month, int day) {
                super.onDateChanged(view, year, month, day);
                calendar.set(year, month, day);
                setTitle(DateFormat.format(format, calendar));
            }
        }
    
        private MyDatePickerDialog mDatePickerDialog;
    
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            mDatePickerDialog = new MyDatePickerDialog(this, this, Calendar.getInstance());
            return mDatePickerDialog;
        }
    
        @Override
        public void onDateSet(DatePicker view, int year, int month, int day) {
            Log.v("DatePickerFragment", "onDateSet");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.