Titanium Community Questions & Answer Archive

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

Button inside a view -> inside a TableViewRow

A cannot manage to make this scenario work: If a button is added inside a View, this view inside a TableViewRow, then the button does not seem to receive click event.
If the same button is added directly inside the Row all is good. Unfortunately i need to place it precisely and thus need this view to put it in.

Anyone has seen this problem ? Any known workarounds ?

Thanks !

Seb

— asked May 19th 2010 by Sebastien PASTOR
  • button
  • inside
  • not
  • responding
  • tableviewrow
  • view
0 Comments

3 Answers

  • Accepted Answer

    Hey Seb,

    Hadn't seen that but tried a quick example and sure enough, I'm seeing the same thing you are.

    Found two weird workarounds that seem to get it working but you have to do them both.

    First is don't use auto for the height and width of your view, and the second is add an event listener to the view. You don't have to use that listener, but having it there allows the button click to be recognized. Told you they were weird. :)

    Here's the code I used:

    // create table view data object
    var data = [];
    
    for (var c=0;c<4;c++)
    {
        data[c] = Ti.UI.createTableViewSection({headerTitle:'Group '+(c+1)});
        for (var x=0;x<10;x++)
        {
            var label = Ti.UI.createLabel({
                text:'Group '+(c+1)+', Row '+(x+1)+"nThis is another line.nCool",
                height:'auto',
                width:'auto',
                left:10
            });
            var rightButton = Titanium.UI.createButton({
                style:Titanium.UI.iPhone.SystemButton.INFO_DARK,
                right:10,
                row:x,
                section:c
            });
            rightButton.addEventListener('click',function(e)
            {
                Ti.API.info('clicked button');
            });
            var tmpView = Ti.UI.createView({height:40,width:40,right:0});
            tmpView.addEventListener('click', function()
            {
                Ti.API.info('clicked view')
            });
            var row = Ti.UI.createTableViewRow({height:'auto'});
            row.add(label);
            tmpView.add(rightButton);
            row.add(tmpView);
            data[c].add(row);
        }
    }
    
    // create table view
    var tableview = Titanium.UI.createTableView({
        data:data,
        style: Titanium.UI.iPhone.TableViewStyle.GROUPED,
        minRowHeight:80,
    });
    
    // add table view to the window
    Titanium.UI.currentWindow.add(tableview);
    
    — answered May 19th 2010 by Dan Giulvezan
    permalink
    1 Comment
    • Perfectly worked for me!!! Thanks Dan. :)

      — commented September 22nd 2011 by Manaday Mavani
  • Ran into this problem on 1.7.2, but did not need to avoid 'auto' (thank heaven) - simply adding a do-nothing listener to my row and (nested) view was sufficient:

    row.addEventListener('click',function(e){});
    view.addEventListener('click',function(e){});
    
    — answered July 30th 2011 by Rob Heittman
    permalink
    0 Comments
  • Hello guys, this is my first post, I hope you can help me. this is my situation: I have a main window with two views inside a Scrollableview. each view has inside 9 buttons that take up all the grandeur of the view. are clickable buttons (each button opens a new window). The problem is this: given that the surface view 1 (and also 2) are fully occupied by the buttons, I can no longer run the swipe to switch from the former to the latter view. How can I make clickable buttons at the same time allowing me to swipe it on them? Thanks to all!

    — answered July 3rd 2012 by nicolò monili
    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.