Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked May 10th 2010 by Donnie Tognazzini
  • buttonbar
  • scroll
  • scrollview
  • tabbedbar
  • view
0 Comments

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
    });
    
    — answered May 10th 2010 by Kevin Whinnery
    permalink
    0 Comments
  • 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.

    — answered May 10th 2010 by Clint Tredway
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.