Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Android DatePicker widget

How does one call the Android DatePicker widget?

I tried…

var win = Titanium.UI.currentWindow;
var picker = Ti.UI.createPicker({type:Titanium.UI.PICKER_TYPE_DATE});
win.add(picker);

and the app dies with the standard 'Sorry…has stopped unexpectedly' message.

— asked April 11th 2010 by rob stevens
  • android
  • datepicker
0 Comments

6 Answers

  • Try this,it works for me.

    var picker = Ti.UI.createPicker();
                    picker.showDatePickerDialog({
                        callback: function(e) {
                            if (e.cancel) {
                                Ti.API.info('user canceled dialog');
                            } else {
                                Ti.API.info('user selected date: ' + e.value);
                            }
                        }
                    });
    win.add(picker);
    
    — answered March 24th 2012 by malar prathap
    permalink
    0 Comments
  • In the documentation it states that date picker doesn't work for Android.

    But I can't even get the regular picked to work for android?? Does this mean we need to use web views until it is implemented?

    — answered April 19th 2010 by Brian KimJohnson
    permalink
    0 Comments
  • As I read it the Docs say there are 5 pickers, _PLAIN, _DATE_AND_TIME, _DATE, _TIME and _COUNT_DOWN_TIMER.

    The docs say "Android does not support the DateTime or Count Down Timer picker type"

    That indicates Android does support the other 3 (_PLAIN, _DATE, _TIME)

    But, as you point out it seems Android does not actually support any.

    — answered April 19th 2010 by rob stevens
    permalink
    0 Comments
  • The API for Pickers was changed post 1.0 and the Android Pickers have not been ported to that new specification from 0.8. Please watch Ticket 808 and you'll be notified when they're ready.

    In the interim, some folks are using the OptionDialog for some items. You could also use a tableview that "picks" the value and closes as well.

    — answered June 3rd 2010 by Don Thorp
    permalink
    1 Comment
    • Can I do multi select in optiondialog? check boxes opposed to options?

      — commented June 3rd 2010 by Conrad McLean
  • THanks this works for me!
    Before this i have very much dificult to get the value of picker in button submit but now its ok!
    I just adapt the function to put the value converted in TextField like:

    var textfield = new Ti.UI.createTextField({etc:etc,etc:etc});
    var picker = Ti.UI.createPicker();

    //Some button call this function in eventlistener:

    somebutton.addEventListener('click',function(e){

    picker.showDatePickerDialog({
    callback: function(e) {
    if (e.cancel) {
    Ti.API.info('user canceled dialog');
    } else {
    var date = new Date(e.value);
    textfield.setText(date.getDate() + '/'+(parseInt(date.getMonth())+1) +'/'+ date.getFullYear());
    //note: january = month (0) so, i just sum + 1 in getMonth for pick right month for display
    }
    }
    });
    });

    — answered April 24th 2012 by Roberto Brasil
    permalink
    0 Comments
  • Similar problem.. I call picker = Titanium.UI.createPicker(), but picker.add(…) fails with TypeError: Cannot call method "add" of null.

    TI1.3 Thx.

    — answered June 3rd 2010 by Conrad McLean
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.