Android - OnDateChangedListener - how do you set this?










53














There is an event listener in Android called DatePicker.OnDateChangedListener.
I am trying to set a DatePicker view's on date changed listener as follows:



DatePicker dp = new DatePicker(getContext());
dp.setOnDateChangedListener(this);
//where this is my activity extends DatePicker.OnDateChangedListener


But guess what?
Date picker does not have a method called setOnDateChangedListener.



My question is:



  1. How then do you set a date changed listener in Android?

  2. If it is not possible to set a date changed listener, what is the purpose for this event?

Any documentation/tutorials will be very helpful.










share|improve this question




























    53














    There is an event listener in Android called DatePicker.OnDateChangedListener.
    I am trying to set a DatePicker view's on date changed listener as follows:



    DatePicker dp = new DatePicker(getContext());
    dp.setOnDateChangedListener(this);
    //where this is my activity extends DatePicker.OnDateChangedListener


    But guess what?
    Date picker does not have a method called setOnDateChangedListener.



    My question is:



    1. How then do you set a date changed listener in Android?

    2. If it is not possible to set a date changed listener, what is the purpose for this event?

    Any documentation/tutorials will be very helpful.










    share|improve this question


























      53












      53








      53


      4





      There is an event listener in Android called DatePicker.OnDateChangedListener.
      I am trying to set a DatePicker view's on date changed listener as follows:



      DatePicker dp = new DatePicker(getContext());
      dp.setOnDateChangedListener(this);
      //where this is my activity extends DatePicker.OnDateChangedListener


      But guess what?
      Date picker does not have a method called setOnDateChangedListener.



      My question is:



      1. How then do you set a date changed listener in Android?

      2. If it is not possible to set a date changed listener, what is the purpose for this event?

      Any documentation/tutorials will be very helpful.










      share|improve this question















      There is an event listener in Android called DatePicker.OnDateChangedListener.
      I am trying to set a DatePicker view's on date changed listener as follows:



      DatePicker dp = new DatePicker(getContext());
      dp.setOnDateChangedListener(this);
      //where this is my activity extends DatePicker.OnDateChangedListener


      But guess what?
      Date picker does not have a method called setOnDateChangedListener.



      My question is:



      1. How then do you set a date changed listener in Android?

      2. If it is not possible to set a date changed listener, what is the purpose for this event?

      Any documentation/tutorials will be very helpful.







      android android-datepicker






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 20 '10 at 18:52









      Georg Fritzsche

      82.9k20170222




      82.9k20170222










      asked Jan 12 '10 at 18:00









      Tawani

      6,125187099




      6,125187099






















          5 Answers
          5






          active

          oldest

          votes


















          100














          Once you've created your DatePicker, you need to initialize it with the date you want to display at first. That's the point at which you can add your listener.



          See DatePicker.init(int, int, int, OnDateChangedListener).






          share|improve this answer


















          • 99




            The Android API is really something. I wonder who came up with this ridiculous approach
            – Tawani
            Jan 28 '10 at 14:36






          • 1




            It doesn't seem that ridiculous to me, and at least it's in the API docs. Anyway, I imagine the reason is because Android widgets usually have several constructors, for when you wish to control what style and layout attributes it should be created with -- so they've kept to that convention rather than creating numerous constructors with many parameters.
            – Christopher Orr
            Jan 28 '10 at 17:09






          • 5




            It does seem appropriate to have a setOnDateChangedListener() method like is present to set a click listener. I wonder why they make you initialize it to a date when it auto initializes to today for you?
            – Ross Hambrick
            Aug 2 '11 at 18:00






          • 1




            @ChristopherOrr the terrible part here is mainly that there is a TimePicker and a DatePicker, which have completely different interfaces. (Wow, old post.... nm)
            – dstibbe
            Oct 29 '15 at 21:46



















          34














          Best way is



           DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
          Calendar calendar = Calendar.getInstance();
          calendar.setTimeInMillis(System.currentTimeMillis());
          datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener()

          @Override
          public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth)
          Log.d("Date", "Year=" + year + " Month=" + (month + 1) + " day=" + dayOfMonth);


          );





          share|improve this answer
















          • 3




            Nice example. thanks.
            – Udi Reshef
            Jan 11 '17 at 14:55










          • Thanks man perfect solution
            – Gowthaman M
            Oct 24 at 13:49


















          11














          This view is in fact a combination of four views, and they are :



          Three Spinners



          One CalendarView



          As of the OnDateChangeListener, the object you passed in to the init method will be simply passed to the contained CalendarView, and I believe that you know that there is a setOnDateChangeListener method in the good old CalendarView...... ......



          In the DatePicker class, there is a method called the getCalendarView, and it is the method you can call if you want to get your hands on the contained CalendarView.



          Once you get your hands on the contained CalendarView, then, needlessly to say, you can call its setOnDateChangeListener






          share|improve this answer
















          • 3




            This is a great workaround for a terrible API. Thanks for this - you just saved my bacon!
            – head in the codes
            Feb 6 '14 at 18:57










          • datePicker.getCalendarView().setOnDateChangeListener() totally works! Thanks! Not very intuitive though. Still think the API should have been datePicker.setOnDateChangeListner().
            – ONE
            Jul 2 '17 at 7:56


















          8














          Something like this:



          DatePicker myDatePicker = (DatePicker) findViewById(R.id.my_date_picker);
          myDatePicker.getCalendarView().setOnDateChangeListener(new CalendarView.OnDateChangeListener()
          @Override
          public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth)
          Log.d("tag", "finally found the listener, the date is: year " + year + ", month " + month + ", dayOfMonth " + dayOfMonth);

          );





          share|improve this answer




















          • It gives UnsupportedOperationException: CalendarView does not exists for the DatePicker
            – turbandroid
            Jan 22 '16 at 17:10






          • 1




            Inflate a DatePicker with android:datePickerMode="spinner" and that Listener worked for me. Without any logical explanation...
            – user2331454
            Apr 26 '16 at 10:13


















          3














          Call init() on the DatePicker object.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2051153%2fandroid-ondatechangedlistener-how-do-you-set-this%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            5 Answers
            5






            active

            oldest

            votes








            5 Answers
            5






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            100














            Once you've created your DatePicker, you need to initialize it with the date you want to display at first. That's the point at which you can add your listener.



            See DatePicker.init(int, int, int, OnDateChangedListener).






            share|improve this answer


















            • 99




              The Android API is really something. I wonder who came up with this ridiculous approach
              – Tawani
              Jan 28 '10 at 14:36






            • 1




              It doesn't seem that ridiculous to me, and at least it's in the API docs. Anyway, I imagine the reason is because Android widgets usually have several constructors, for when you wish to control what style and layout attributes it should be created with -- so they've kept to that convention rather than creating numerous constructors with many parameters.
              – Christopher Orr
              Jan 28 '10 at 17:09






            • 5




              It does seem appropriate to have a setOnDateChangedListener() method like is present to set a click listener. I wonder why they make you initialize it to a date when it auto initializes to today for you?
              – Ross Hambrick
              Aug 2 '11 at 18:00






            • 1




              @ChristopherOrr the terrible part here is mainly that there is a TimePicker and a DatePicker, which have completely different interfaces. (Wow, old post.... nm)
              – dstibbe
              Oct 29 '15 at 21:46
















            100














            Once you've created your DatePicker, you need to initialize it with the date you want to display at first. That's the point at which you can add your listener.



            See DatePicker.init(int, int, int, OnDateChangedListener).






            share|improve this answer


















            • 99




              The Android API is really something. I wonder who came up with this ridiculous approach
              – Tawani
              Jan 28 '10 at 14:36






            • 1




              It doesn't seem that ridiculous to me, and at least it's in the API docs. Anyway, I imagine the reason is because Android widgets usually have several constructors, for when you wish to control what style and layout attributes it should be created with -- so they've kept to that convention rather than creating numerous constructors with many parameters.
              – Christopher Orr
              Jan 28 '10 at 17:09






            • 5




              It does seem appropriate to have a setOnDateChangedListener() method like is present to set a click listener. I wonder why they make you initialize it to a date when it auto initializes to today for you?
              – Ross Hambrick
              Aug 2 '11 at 18:00






            • 1




              @ChristopherOrr the terrible part here is mainly that there is a TimePicker and a DatePicker, which have completely different interfaces. (Wow, old post.... nm)
              – dstibbe
              Oct 29 '15 at 21:46














            100












            100








            100






            Once you've created your DatePicker, you need to initialize it with the date you want to display at first. That's the point at which you can add your listener.



            See DatePicker.init(int, int, int, OnDateChangedListener).






            share|improve this answer














            Once you've created your DatePicker, you need to initialize it with the date you want to display at first. That's the point at which you can add your listener.



            See DatePicker.init(int, int, int, OnDateChangedListener).







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 4 at 15:58









            Alireza Noorali

            1,391633




            1,391633










            answered Jan 12 '10 at 18:11









            Christopher Orr

            94.4k20172175




            94.4k20172175







            • 99




              The Android API is really something. I wonder who came up with this ridiculous approach
              – Tawani
              Jan 28 '10 at 14:36






            • 1




              It doesn't seem that ridiculous to me, and at least it's in the API docs. Anyway, I imagine the reason is because Android widgets usually have several constructors, for when you wish to control what style and layout attributes it should be created with -- so they've kept to that convention rather than creating numerous constructors with many parameters.
              – Christopher Orr
              Jan 28 '10 at 17:09






            • 5




              It does seem appropriate to have a setOnDateChangedListener() method like is present to set a click listener. I wonder why they make you initialize it to a date when it auto initializes to today for you?
              – Ross Hambrick
              Aug 2 '11 at 18:00






            • 1




              @ChristopherOrr the terrible part here is mainly that there is a TimePicker and a DatePicker, which have completely different interfaces. (Wow, old post.... nm)
              – dstibbe
              Oct 29 '15 at 21:46













            • 99




              The Android API is really something. I wonder who came up with this ridiculous approach
              – Tawani
              Jan 28 '10 at 14:36






            • 1




              It doesn't seem that ridiculous to me, and at least it's in the API docs. Anyway, I imagine the reason is because Android widgets usually have several constructors, for when you wish to control what style and layout attributes it should be created with -- so they've kept to that convention rather than creating numerous constructors with many parameters.
              – Christopher Orr
              Jan 28 '10 at 17:09






            • 5




              It does seem appropriate to have a setOnDateChangedListener() method like is present to set a click listener. I wonder why they make you initialize it to a date when it auto initializes to today for you?
              – Ross Hambrick
              Aug 2 '11 at 18:00






            • 1




              @ChristopherOrr the terrible part here is mainly that there is a TimePicker and a DatePicker, which have completely different interfaces. (Wow, old post.... nm)
              – dstibbe
              Oct 29 '15 at 21:46








            99




            99




            The Android API is really something. I wonder who came up with this ridiculous approach
            – Tawani
            Jan 28 '10 at 14:36




            The Android API is really something. I wonder who came up with this ridiculous approach
            – Tawani
            Jan 28 '10 at 14:36




            1




            1




            It doesn't seem that ridiculous to me, and at least it's in the API docs. Anyway, I imagine the reason is because Android widgets usually have several constructors, for when you wish to control what style and layout attributes it should be created with -- so they've kept to that convention rather than creating numerous constructors with many parameters.
            – Christopher Orr
            Jan 28 '10 at 17:09




            It doesn't seem that ridiculous to me, and at least it's in the API docs. Anyway, I imagine the reason is because Android widgets usually have several constructors, for when you wish to control what style and layout attributes it should be created with -- so they've kept to that convention rather than creating numerous constructors with many parameters.
            – Christopher Orr
            Jan 28 '10 at 17:09




            5




            5




            It does seem appropriate to have a setOnDateChangedListener() method like is present to set a click listener. I wonder why they make you initialize it to a date when it auto initializes to today for you?
            – Ross Hambrick
            Aug 2 '11 at 18:00




            It does seem appropriate to have a setOnDateChangedListener() method like is present to set a click listener. I wonder why they make you initialize it to a date when it auto initializes to today for you?
            – Ross Hambrick
            Aug 2 '11 at 18:00




            1




            1




            @ChristopherOrr the terrible part here is mainly that there is a TimePicker and a DatePicker, which have completely different interfaces. (Wow, old post.... nm)
            – dstibbe
            Oct 29 '15 at 21:46





            @ChristopherOrr the terrible part here is mainly that there is a TimePicker and a DatePicker, which have completely different interfaces. (Wow, old post.... nm)
            – dstibbe
            Oct 29 '15 at 21:46














            34














            Best way is



             DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener()

            @Override
            public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth)
            Log.d("Date", "Year=" + year + " Month=" + (month + 1) + " day=" + dayOfMonth);


            );





            share|improve this answer
















            • 3




              Nice example. thanks.
              – Udi Reshef
              Jan 11 '17 at 14:55










            • Thanks man perfect solution
              – Gowthaman M
              Oct 24 at 13:49















            34














            Best way is



             DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener()

            @Override
            public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth)
            Log.d("Date", "Year=" + year + " Month=" + (month + 1) + " day=" + dayOfMonth);


            );





            share|improve this answer
















            • 3




              Nice example. thanks.
              – Udi Reshef
              Jan 11 '17 at 14:55










            • Thanks man perfect solution
              – Gowthaman M
              Oct 24 at 13:49













            34












            34








            34






            Best way is



             DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener()

            @Override
            public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth)
            Log.d("Date", "Year=" + year + " Month=" + (month + 1) + " day=" + dayOfMonth);


            );





            share|improve this answer












            Best way is



             DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker);
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener()

            @Override
            public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth)
            Log.d("Date", "Year=" + year + " Month=" + (month + 1) + " day=" + dayOfMonth);


            );






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 22 '16 at 17:20









            turbandroid

            1,7601730




            1,7601730







            • 3




              Nice example. thanks.
              – Udi Reshef
              Jan 11 '17 at 14:55










            • Thanks man perfect solution
              – Gowthaman M
              Oct 24 at 13:49












            • 3




              Nice example. thanks.
              – Udi Reshef
              Jan 11 '17 at 14:55










            • Thanks man perfect solution
              – Gowthaman M
              Oct 24 at 13:49







            3




            3




            Nice example. thanks.
            – Udi Reshef
            Jan 11 '17 at 14:55




            Nice example. thanks.
            – Udi Reshef
            Jan 11 '17 at 14:55












            Thanks man perfect solution
            – Gowthaman M
            Oct 24 at 13:49




            Thanks man perfect solution
            – Gowthaman M
            Oct 24 at 13:49











            11














            This view is in fact a combination of four views, and they are :



            Three Spinners



            One CalendarView



            As of the OnDateChangeListener, the object you passed in to the init method will be simply passed to the contained CalendarView, and I believe that you know that there is a setOnDateChangeListener method in the good old CalendarView...... ......



            In the DatePicker class, there is a method called the getCalendarView, and it is the method you can call if you want to get your hands on the contained CalendarView.



            Once you get your hands on the contained CalendarView, then, needlessly to say, you can call its setOnDateChangeListener






            share|improve this answer
















            • 3




              This is a great workaround for a terrible API. Thanks for this - you just saved my bacon!
              – head in the codes
              Feb 6 '14 at 18:57










            • datePicker.getCalendarView().setOnDateChangeListener() totally works! Thanks! Not very intuitive though. Still think the API should have been datePicker.setOnDateChangeListner().
              – ONE
              Jul 2 '17 at 7:56















            11














            This view is in fact a combination of four views, and they are :



            Three Spinners



            One CalendarView



            As of the OnDateChangeListener, the object you passed in to the init method will be simply passed to the contained CalendarView, and I believe that you know that there is a setOnDateChangeListener method in the good old CalendarView...... ......



            In the DatePicker class, there is a method called the getCalendarView, and it is the method you can call if you want to get your hands on the contained CalendarView.



            Once you get your hands on the contained CalendarView, then, needlessly to say, you can call its setOnDateChangeListener






            share|improve this answer
















            • 3




              This is a great workaround for a terrible API. Thanks for this - you just saved my bacon!
              – head in the codes
              Feb 6 '14 at 18:57










            • datePicker.getCalendarView().setOnDateChangeListener() totally works! Thanks! Not very intuitive though. Still think the API should have been datePicker.setOnDateChangeListner().
              – ONE
              Jul 2 '17 at 7:56













            11












            11








            11






            This view is in fact a combination of four views, and they are :



            Three Spinners



            One CalendarView



            As of the OnDateChangeListener, the object you passed in to the init method will be simply passed to the contained CalendarView, and I believe that you know that there is a setOnDateChangeListener method in the good old CalendarView...... ......



            In the DatePicker class, there is a method called the getCalendarView, and it is the method you can call if you want to get your hands on the contained CalendarView.



            Once you get your hands on the contained CalendarView, then, needlessly to say, you can call its setOnDateChangeListener






            share|improve this answer












            This view is in fact a combination of four views, and they are :



            Three Spinners



            One CalendarView



            As of the OnDateChangeListener, the object you passed in to the init method will be simply passed to the contained CalendarView, and I believe that you know that there is a setOnDateChangeListener method in the good old CalendarView...... ......



            In the DatePicker class, there is a method called the getCalendarView, and it is the method you can call if you want to get your hands on the contained CalendarView.



            Once you get your hands on the contained CalendarView, then, needlessly to say, you can call its setOnDateChangeListener







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 16 '13 at 9:38









            user2389347

            11112




            11112







            • 3




              This is a great workaround for a terrible API. Thanks for this - you just saved my bacon!
              – head in the codes
              Feb 6 '14 at 18:57










            • datePicker.getCalendarView().setOnDateChangeListener() totally works! Thanks! Not very intuitive though. Still think the API should have been datePicker.setOnDateChangeListner().
              – ONE
              Jul 2 '17 at 7:56












            • 3




              This is a great workaround for a terrible API. Thanks for this - you just saved my bacon!
              – head in the codes
              Feb 6 '14 at 18:57










            • datePicker.getCalendarView().setOnDateChangeListener() totally works! Thanks! Not very intuitive though. Still think the API should have been datePicker.setOnDateChangeListner().
              – ONE
              Jul 2 '17 at 7:56







            3




            3




            This is a great workaround for a terrible API. Thanks for this - you just saved my bacon!
            – head in the codes
            Feb 6 '14 at 18:57




            This is a great workaround for a terrible API. Thanks for this - you just saved my bacon!
            – head in the codes
            Feb 6 '14 at 18:57












            datePicker.getCalendarView().setOnDateChangeListener() totally works! Thanks! Not very intuitive though. Still think the API should have been datePicker.setOnDateChangeListner().
            – ONE
            Jul 2 '17 at 7:56




            datePicker.getCalendarView().setOnDateChangeListener() totally works! Thanks! Not very intuitive though. Still think the API should have been datePicker.setOnDateChangeListner().
            – ONE
            Jul 2 '17 at 7:56











            8














            Something like this:



            DatePicker myDatePicker = (DatePicker) findViewById(R.id.my_date_picker);
            myDatePicker.getCalendarView().setOnDateChangeListener(new CalendarView.OnDateChangeListener()
            @Override
            public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth)
            Log.d("tag", "finally found the listener, the date is: year " + year + ", month " + month + ", dayOfMonth " + dayOfMonth);

            );





            share|improve this answer




















            • It gives UnsupportedOperationException: CalendarView does not exists for the DatePicker
              – turbandroid
              Jan 22 '16 at 17:10






            • 1




              Inflate a DatePicker with android:datePickerMode="spinner" and that Listener worked for me. Without any logical explanation...
              – user2331454
              Apr 26 '16 at 10:13















            8














            Something like this:



            DatePicker myDatePicker = (DatePicker) findViewById(R.id.my_date_picker);
            myDatePicker.getCalendarView().setOnDateChangeListener(new CalendarView.OnDateChangeListener()
            @Override
            public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth)
            Log.d("tag", "finally found the listener, the date is: year " + year + ", month " + month + ", dayOfMonth " + dayOfMonth);

            );





            share|improve this answer




















            • It gives UnsupportedOperationException: CalendarView does not exists for the DatePicker
              – turbandroid
              Jan 22 '16 at 17:10






            • 1




              Inflate a DatePicker with android:datePickerMode="spinner" and that Listener worked for me. Without any logical explanation...
              – user2331454
              Apr 26 '16 at 10:13













            8












            8








            8






            Something like this:



            DatePicker myDatePicker = (DatePicker) findViewById(R.id.my_date_picker);
            myDatePicker.getCalendarView().setOnDateChangeListener(new CalendarView.OnDateChangeListener()
            @Override
            public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth)
            Log.d("tag", "finally found the listener, the date is: year " + year + ", month " + month + ", dayOfMonth " + dayOfMonth);

            );





            share|improve this answer












            Something like this:



            DatePicker myDatePicker = (DatePicker) findViewById(R.id.my_date_picker);
            myDatePicker.getCalendarView().setOnDateChangeListener(new CalendarView.OnDateChangeListener()
            @Override
            public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth)
            Log.d("tag", "finally found the listener, the date is: year " + year + ", month " + month + ", dayOfMonth " + dayOfMonth);

            );






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 9 '15 at 18:51









            Andrew

            1,78141928




            1,78141928











            • It gives UnsupportedOperationException: CalendarView does not exists for the DatePicker
              – turbandroid
              Jan 22 '16 at 17:10






            • 1




              Inflate a DatePicker with android:datePickerMode="spinner" and that Listener worked for me. Without any logical explanation...
              – user2331454
              Apr 26 '16 at 10:13
















            • It gives UnsupportedOperationException: CalendarView does not exists for the DatePicker
              – turbandroid
              Jan 22 '16 at 17:10






            • 1




              Inflate a DatePicker with android:datePickerMode="spinner" and that Listener worked for me. Without any logical explanation...
              – user2331454
              Apr 26 '16 at 10:13















            It gives UnsupportedOperationException: CalendarView does not exists for the DatePicker
            – turbandroid
            Jan 22 '16 at 17:10




            It gives UnsupportedOperationException: CalendarView does not exists for the DatePicker
            – turbandroid
            Jan 22 '16 at 17:10




            1




            1




            Inflate a DatePicker with android:datePickerMode="spinner" and that Listener worked for me. Without any logical explanation...
            – user2331454
            Apr 26 '16 at 10:13




            Inflate a DatePicker with android:datePickerMode="spinner" and that Listener worked for me. Without any logical explanation...
            – user2331454
            Apr 26 '16 at 10:13











            3














            Call init() on the DatePicker object.






            share|improve this answer

























              3














              Call init() on the DatePicker object.






              share|improve this answer























                3












                3








                3






                Call init() on the DatePicker object.






                share|improve this answer












                Call init() on the DatePicker object.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 12 '10 at 18:11









                CommonsWare

                763k13818611909




                763k13818611909



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid …


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid …


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2051153%2fandroid-ondatechangedlistener-how-do-you-set-this%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    ReactJS Fetched API data displays live - need Data displayed static

                    政党