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.
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);
-
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?
-
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.
-
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.
-
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
}
}
});
}); -
Similar problem.. I call picker = Titanium.UI.createPicker(), but picker.add(…) fails with TypeError: Cannot call method "add" of null.
TI1.3 Thx.