ButtonBar in nested view not getting click events.
I have the following:
var scrollView = Titanium.UI.createScrollView({
contentWidth:'auto',
contentHeight:'auto',
top:0,
left:0,
width:'100%',
height:'100%',
layout : 'vertical',
showVerticalScrollIndicator:true
});
var dayOfWeekView = Ti.UI.createView({
top : 10,
width: 250,
left : 30
});
dayOfWeekView.add(Ti.UI.createLabel({
text:'Days',
left:0,
width:80,
height:'auto',
color:'white'
}));
var bar = Titanium.UI.createButtonBar({
labels: ["M", "T", "W", "Th", "F", "Sa", "Su"],
backgroundColor:'#999',
left: 85,
style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
height:30
});
bar.addEventListener( 'click', function() {
alert('you will never see me!');
});
dayOfWeekView.add(bar);
scrollView.add(dayOfWeekView);
Titanium.UI.currentWindow.add(scrollView);
I'm trying to "click" on the button bar. I never see the alert nor are any of the buttons "selected" (i.e. the down effect is shown).
I tried this same code with a TabbedBar as well. No luck.
Any ideas?
2 Answers
-
Accepted Answer
Give your
dayOfWeekView
a fixed height - this allowed me to start getting click events on the button bar.var dayOfWeekView = Ti.UI.createView({ top : 10, width: 250, left : 30, height: 150 });
-
something else you can do is to pass the event into your function like this:
bar.addEventListener( 'click', function(e) { alert('you will never see me! ' e.index); });
This will give you the index of the button that was pressed.