Android - OnDateChangedListener - how do you set this?











up vote
52
down vote

favorite
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




























    up vote
    52
    down vote

    favorite
    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


























      up vote
      52
      down vote

      favorite
      4









      up vote
      52
      down vote

      favorite
      4






      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.5k20170222




      82.5k20170222










      asked Jan 12 '10 at 18:00









      Tawani

      6,090187098




      6,090187098
























          5 Answers
          5






          active

          oldest

          votes

















          up vote
          100
          down vote



          accepted










          Once you've created your DatePicker, you need to initialise 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

















          • 98




            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




















          up vote
          34
          down vote













          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


















          up vote
          11
          down vote













          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


















          up vote
          8
          down vote













          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


















          up vote
          3
          down vote













          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',
            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








            up vote
            100
            down vote



            accepted










            Once you've created your DatePicker, you need to initialise 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

















            • 98




              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

















            up vote
            100
            down vote



            accepted










            Once you've created your DatePicker, you need to initialise 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

















            • 98




              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















            up vote
            100
            down vote



            accepted







            up vote
            100
            down vote



            accepted






            Once you've created your DatePicker, you need to initialise 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 initialise 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










            answered Jan 12 '10 at 18:11









            Christopher Orr

            93.8k20171175




            93.8k20171175








            • 98




              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
















            • 98




              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










            98




            98




            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














            up vote
            34
            down vote













            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















            up vote
            34
            down vote













            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













            up vote
            34
            down vote










            up vote
            34
            down vote









            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,7201629




            1,7201629








            • 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










            up vote
            11
            down vote













            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















            up vote
            11
            down vote













            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













            up vote
            11
            down vote










            up vote
            11
            down vote









            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










            up vote
            8
            down vote













            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















            up vote
            8
            down vote













            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













            up vote
            8
            down vote










            up vote
            8
            down vote









            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,74641928




            1,74641928












            • 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










            up vote
            3
            down vote













            Call init() on the DatePicker object.






            share|improve this answer

























              up vote
              3
              down vote













              Call init() on the DatePicker object.






              share|improve this answer























                up vote
                3
                down vote










                up vote
                3
                down vote









                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

                756k13618441897




                756k13618441897






























                     

                    draft saved


                    draft discarded



















































                     


                    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

                    List item for chat from Array inside array React Native

                    Thiostrepton

                    Caerphilly