I want to hide the picker below when someone clicks outside of the picker. Like if they click on another textbox, the picker should disappear.
How can I do that?
//onClick trigger for date buttons: exp_year1.addEventListener('focus', function(e) { Titanium.API.info('Triggered focus on date txtField'); exp_year1.blur(); var winDatePicker1 = Titanium.UI.currentWindow; var minDate = new Date(); var year = minDate.getFullYear(); var picker1 = Ti.UI.createPicker({ bottom : 0 }); Titanium.API.info('1'); var data = []; for(var i = year; i < year + 50; i += 1) { var t = i.toString(); var row = Ti.UI.createPickerRow({title : t}); data.push(row); } picker1.add(data); picker1.selectionIndicator = true; Titanium.API.info('3'); var done1 = Ti.UI.createImageView({ title : '', width : 80, right : 12, height : 40, image : '../images/done.gif', }); var toolbar1 = Ti.UI.createView({ height : 43, backgroundImage : '../images/toolbar.gif', }); toolbar1.add(done1); done1.addEventListener('click', function() { toolbar1.hide(); picker1.hide(); Titanium.API.info('gone'); }); winDatePicker1.addEventListener('click', function() { toolbar1.hide(); picker1.hide(); Titanium.API.info('gone2'); }); fview.addEventListener('click', function() { toolbar1.hide(); picker1.hide(); Titanium.API.info('gone2'); }); Titanium.API.info('4'); picker1.addEventListener('change', function(e) { var val = e.row.title; Titanium.API.info('E value = ' + val); var newv = val; exp_year1.setValue(newv); }); Titanium.API.info('5'); winDatePicker1.add(picker1); winDatePicker1.add(toolbar1); Titanium.API.info('6'); winDatePicker1.show({ view : exp_year1, animated : true }); });
5 Answers
Accepted Answer
I'd do it with a little simple trickery... I would create another transparent view to hide/show along with the picker, that takes up 100% of the screen behind the picker & toolbar. Then set the click listener on that to dismiss the picker.
Hi i would say that you just create
var slide_in = Titanium.UI.createAnimation({ bottom : 0, cause : 'slideIn' }); var slide_out = Titanium.UI.createAnimation({ bottom : -251, cause : 'slideOut' }); Window.addEventListener('click',function(e){ picker_view.animate(myProfile.child.slide_out)// to Hide the picker });
SlideIn Variable is for showing it and slideOut variable is for getting it below the screen. pls adjust the bottom property as per your requirement. and pls mark the answer as permanent if you problem is solved
There is no predefined method to hide or blur the picker according to api .
You can add picker to a view and show or hide that view as per requirement
its a bug ' textfield click event never gets fired' ,
1.add picker to a view 2.use focus event for hiding pickerview
textfile.addEventListener('focus',function(){ picker_view.hide(); })
Your Answer
Think you can help? Login to answer this question!