Problem description
Adding a picker to an alert dialog does not work on Android.
Steps to reproduce
- Use this code to reproduce the bug:
var win = Titanium.UI.createWindow({
title : 'Bug Isolation',
backgroundColor : 'white',
barColor : '#0066CC',
navBarHidden : false,
tabBarHidden : true
});
var alertView = Ti.UI.createView({
top : '0dp'
});
var monthPicker = Ti.UI.createPicker({
top : '5dp',
width : '150dp',
left : '5dp'
});
var months = [];
months[0]=Ti.UI.createPickerRow({title:'January'});
months[1]=Ti.UI.createPickerRow({title:'February'});
months[2]=Ti.UI.createPickerRow({title:'March'});
months[3]=Ti.UI.createPickerRow({title:'April'});
months[4]=Ti.UI.createPickerRow({title:'May'});
months[5]=Ti.UI.createPickerRow({title:'June'});
months[6]=Ti.UI.createPickerRow({title:'July'});
months[7]=Ti.UI.createPickerRow({title:'August'});
months[8]=Ti.UI.createPickerRow({title:'September'});
months[9]=Ti.UI.createPickerRow({title:'October'});
months[10]=Ti.UI.createPickerRow({title:'November'});
months[11]=Ti.UI.createPickerRow({title:'December'});
monthPicker.add(months);
monthPicker.selectionIndicator = true;
var yearPicker = Ti.UI.createPicker({
top : '5dp',
width : '100dp',
right : '5dp'
});
var years = [];
var yearRange = {min: new Date().getFullYear(), max: (new Date().getFullYear() + 10)}
for (var i = yearRange.min; i <= yearRange.max; i++){
var item = Ti.UI.createPickerRow({title: i.toString()});
years.push(item);
}
yearPicker.add(years);
yearPicker.selectionIndicator = true;
alertView.add(monthPicker);
alertView.add(yearPicker);
var expDateAlert = Ti.UI.createAlertDialog({
title : 'Exp. Date:',
buttonNames : ['Set', 'Cancel'],
cancel : 1,
androidView : alertView
});
expDateAlert.addEventListener('click', function(e){
if (e.index == 0){
Ti.API.info('monthPicker: ' + JSON.stringify(monthPicker.getSelectedRow(0).title));
Ti.API.info('yearPicker: ' + JSON.stringify(yearPicker.getSelectedRow(0).title));
}
});
var button = Ti.UI.createButton({
title : 'click me',
bottom : '5dp',
height : '50dp',
width : '200dp'
});
button.addEventListener('click', function(e){
expDateAlert.show();
});
win.add(button);
win.open();
- Run the app and click the button: a dialog appears
- Try to use the picker views: they won't work
PR: https://github.com/appcelerator/titanium_mobile/pull/3525
Backport PR https://github.com/appcelerator/titanium_mobile/pull/3733 Backport task TIMOB-12341
Environment used for verification - Titanium SDK: 3.1.0.v20130114171802 Titanium Studio:3.0.1.201212181159 Device: Samsung GALAXY Note (2.3.6)
Also verified on tab nexus 7 android 4.1 And Titanium SDK: 3.0.2.v20130118180632
I am able to reproduce this issue. It works fine on SDK:3.1.1.GA, issue exist on SDK: 3.1.3.GA, 3.1.2.GA Steps to reproduce: 1. Run the above app. 2. Click on click me button 3. Click on the month picker 4. Click on Set and Cancel button Expected: The alert dialog closes and no error is shown. Picked month and year are printed on console. Actual: Runtime Exception is occured as" 12-05 17:10:43.091: E/TiExceptionHandler(29802): (main) [25082,25082] ----- Titanium Javascript Runtime Error ----- 12-05 17:10:43.091: E/TiExceptionHandler(29802): (main) [0,25082] - In acceptance.js:640,70 12-05 17:10:43.091: E/TiExceptionHandler(29802): (main) [1,25083] - Message: Uncaught TypeError: Cannot read property 'title' of null 12-05 17:10:43.091: E/TiExceptionHandler(29802): (main) [0,25083] - Source: API.info('yearPicker: ' + JSON.stringify(yearPicker.getSelectedRow(0).title)); 12-05 17:10:43.111: E/V8Exception(29802): Exception occurred at acceptance.js:640: Uncaught TypeError: Cannot read property 'title' of null"
[~hpham] This issue still exists on android.