I am trying to make a dynamic picker which is working fine on iOS but on android there's no chance, here is my code
function showPicker(data, lbl, parentView) { var picker_view; var pickerHeight = 251; var slide_in = Titanium.UI.createAnimation({ bottom : 0 }); var slide_out = Titanium.UI.createAnimation({ bottom : -pickerHeight }); picker_view = Titanium.UI.createView({ height : pickerHeight, bottom : -pickerHeight, zIndex : 1000 }); var cancel = Titanium.UI.createButton({ title : 'Cancel', style : Titanium.UI.iPhone.SystemButtonStyle.BORDERED }); var done = Titanium.UI.createButton({ title : 'Done', style : Titanium.UI.iPhone.SystemButtonStyle.DONE }); var spacer = Titanium.UI.createButton({ systemButton : Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE }); // var toolbar = Titanium.UI.iOS.createToolbar({ // top : 0, // items : [cancel, spacer, done] // }); var picker = Titanium.UI.createPicker({ top : (2 * height_unit), selectionIndicator : true, width : win_width - (15 * width_unit), }); if (lbl.id == "complaintype") { for (var i = 0; i < data.length; i++) { alert(i); picker.add(Ti.UI.createPickerRow({ title : claimantTypeData[i], //_id : i + 1 })); } } cancel.addEventListener('click', function() { picker_view.animate(slide_out); }); done.addEventListener('click', function() { lbl.text = " " + picker.getSelectedRow(0).title; lbl.color = 'black'; picker_view.animate(slide_out); if (lbl.id == "sitecode") { siteid = picker.getSelectedRow(0)._id; } else { complaintype = picker.getSelectedRow(0)._id; } }); lbl.addEventListener('focus', function() { picker_view.animate(slide_out); }); parentView.addEventListener('click', function() { if (lbl.id == "sitecode") { if (siteCodeData.length == 0) { activityIndicator.show(); getSiteCodeData(function(serverResponse) { var length = serverResponse.length; for (var i = 0; i < length; i++) { siteCodeData.push(serverResponse[i].actName); picker.add(Ti.UI.createPickerRow({ title : siteCodeData[i], _id : JSON.parse(serverResponse[i].actCode) })); } activityIndicator.hide(); //picker_view.add(toolbar); picker_view.add(picker); picker_view.animate(slide_in); }); } else { //picker_view.add(toolbar); picker_view.add(picker); picker_view.animate(slide_in); } } else { //picker_view.add(toolbar); picker_view.add(picker); picker_view.animate(slide_in); } }); return picker_view; }
//This function calls ws for getting site code and name. function getSiteCodeData(callback) { if (Titanium.Network.networkType != Titanium.Network.NETWORK_NONE) { var xhr = Titanium.Network.createHTTPClient({ onload : function(e) { callback(JSON.parse(this.responseText).acts); }, onerror : function(e) { activityIndicator.hide(); alert("Can not get server response"); } }); xhr.open('GET', 'http://89.237.149.36/ws/resources/shop/acts'); xhr.send(); } else { alert("No network avialable."); } } function pickerParentView(hintText) { var parentView = Titanium.UI.createView({ height : 40, width : 280, borderRadius : 3, top : 20, backgroundColor : "#FFFFFF", layout : "horizontal", }); var lbl = Titanium.UI.createLabel({ text : hintText, color : 'gray', width : '75%', height : 40, left : 5, //right : 5, textAlign : 'center' }); if (hintText == hintComplainType) { lbl.id = "complaintype"; } else { lbl.id = "sitecode"; } var drop_buttonParent = Titanium.UI.createView({ width : '20%', height : 40 }); var drop_buttonChild = Titanium.UI.createImageView({ image : "/images/button_downArrow.png", width : 15, height : 11 }); drop_buttonParent.add(drop_buttonChild); parentView.add(lbl); parentView.add(drop_buttonParent); return parentView; } var codeView = pickerParentView(hintSiteCode); formView.add(codeView); formView.add(showPicker(siteCodeData, codeView.children[0], codeView));