Row click stops working if have native checkbox

You must Login before you can answer or comment on any questions.

If I add native checkbox, row click stops working and works only on labels. The empty areas in row not work on click. Here is the code:

var paidSwitch = Titanium.UI.createSwitch({
                  top:5,
                  left:0,
                  width:50,     
                  style:Titanium.UI.Android.SWITCH_STYLE_CHECKBOX,
                  arrow: true,                
                  touchEnabled:true,                    
                  value:false,
                });
                var paidCheckbox = Titanium.UI.createImageView({
                  image:'../images/unchecked.png',
                  width:20,
                  height:30,
                  top:0,
                  left:0,
                  arrow: false,               
                  visible: false
                });
 
                var label = Ti.UI.createLabel({
                    text:title,
                    left:40,
                    top:0,
                    arrow: false,
                    touchEnabled:true,                  
                    font:{fontColor:"#666666",fontSize:14,fontWeight:'bold', fontFamily:'Arial'},
                    color:'#666666' 
                });
                var labeledit = Ti.UI.createLabel({
                    text:item.getElementsByTagName("ReceiveDate").item(0).text,
                    left:265,
                    textAlign:'center',
                    top:0,
                    arrow: false,
                    touchEnabled:true,                  
                    font:{fontColor:"#000000",fontSize:13,fontWeight:'bold', fontFamily:'Arial'},
                    color:'#000000' 
                });
                title = item.getElementsByTagName("ShortSubject").item(0).text;
                var labelstate = Ti.UI.createLabel({
                    text:title,
                    left:40,
                    arrow: false,
                    touchEnabled:true,                  
                    top:20,
                    font:{fontColor:"#000000",fontSize:11,fontWeight:'bold', fontFamily:'Arial'},
                    color:'#000000' 
                });
                title = item.getElementsByTagName("ShortBody").item(0).text;
                var labelbody = Ti.UI.createLabel({
                    text:title,
                    left:40,
                    top:35,
                    arrow: false,
                    touchEnabled:true,                  
                    font:{fontColor:"#515151",fontSize:12,fontFamily:'Arial'},
                    color:'#515151' 
                });
                title = item.getElementsByTagName("ID").item(0).text;
                var lblID = Ti.UI.createLabel({
                    text:title,
                    left:100,
                    top:0,
                    arrow: false,
                    touchEnabled:true,                  
                    visible:false,
                    font:{fontColor:"#515151",fontSize:12,fontFamily:'Arial'},
                    color:'#515151' 
                });
                var CheckedCheckbox = Titanium.UI.createImageView({
                  image:'../images/checked.png',
                  width:20,
                  height:20,
                  top:0,
                  visible:false,
                  left:0
                });
                row.add(paidSwitch);
                row.add(paidCheckbox);
                row.add(label);
                row.add(labeledit);
                row.add(labelstate);        
                row.add(labelbody);
                row.add(lblID);
                row.add(CheckedCheckbox);
                if(item.getElementsByTagName("FlagStatus").item(0).text == 0){
                    row.backgroundColor = '#ffffff';
                }
                else{
                    row.backgroundColor = '#cccccc';
                }
                data[x++] = row;
var tableview = Titanium.UI.createTableView({
                        data:data,
                        top:40
                        });
        Titanium.UI.currentWindow.add(tableview);

1 Answer

I don't see where you created "row", but you need touchEnabled=false on the labels, and touchEnabled=true on the TableViewRow (if that's what "row" is). Don't specify touchEnabled at all on the Switch.<br> <br> Beware that you may find that the switches don't repaint themselves if the parent of the TableView has layout set to 'vertical'. I think this is a TableView bug.

— answered 2 years ago by Shawn Lipscomb
answer permalink
2 Comments
  • Thanks shawn for your reply. I have tried it and now it stops working on whole row. Here is complete code:

    var paidSwitch = Titanium.UI.createSwitch({
                      top:5,
                      left:0,
                      width:50,     
                      style:Titanium.UI.Android.SWITCH_STYLE_CHECKBOX,
                      arrow: true,                
                      value:false,
                    });
                    var paidCheckbox = Titanium.UI.createImageView({
                      image:'../images/unchecked.png',
                      width:20,
                      touchEnabled:false,
                      height:30,
                      top:0,
                      left:0,
                      arrow: false,               
                      visible: false
                    });
     
                    var label = Ti.UI.createLabel({
                        text:title,
                        left:40,
                        top:0,
                        arrow: false,
                        touchEnabled:false,                 
                        font:{fontColor:"#666666",fontSize:14,fontWeight:'bold', fontFamily:'Arial'},
                        color:'#666666' 
                    });
                    var labeledit = Ti.UI.createLabel({
                        text:item.getElementsByTagName("ReceiveDate").item(0).text,
                        left:265,
                        textAlign:'center',
                        top:0,
                        arrow: false,
                        touchEnabled:false,                 
                        font:{fontColor:"#000000",fontSize:13,fontWeight:'bold', fontFamily:'Arial'},
                        color:'#000000' 
                    });
                    title = item.getElementsByTagName("ShortSubject").item(0).text;
                    var labelstate = Ti.UI.createLabel({
                        text:title,
                        left:40,
                        arrow: false,
                        touchEnabled:false,                 
                        top:20,
                        font:{fontColor:"#000000",fontSize:11,fontWeight:'bold', fontFamily:'Arial'},
                        color:'#000000' 
                    });
                    title = item.getElementsByTagName("ShortBody").item(0).text;
                    var labelbody = Ti.UI.createLabel({
                        text:title,
                        left:40,
                        top:35,
                        arrow: false,
                        touchEnabled:false,                 
                        font:{fontColor:"#515151",fontSize:12,fontFamily:'Arial'},
                        color:'#515151' 
                    });
                    title = item.getElementsByTagName("ID").item(0).text;
                    var lblID = Ti.UI.createLabel({
                        text:title,
                        left:100,
                        top:0,
                        arrow: false,
                        touchEnabled:false,                 
                        visible:false,
                        font:{fontColor:"#515151",fontSize:12,fontFamily:'Arial'},
                        color:'#515151' 
                    });
                    var CheckedCheckbox = Titanium.UI.createImageView({
                      image:'../images/checked.png',
                      width:20,
                      height:20,
                      top:0,
                      visible:false,
                      touchEnabled:false,
                      left:0
                    });
                    row.add(paidSwitch);
                    row.add(paidCheckbox);
                    row.add(label);
                    row.add(labeledit);
                    row.add(labelstate);        
                    row.add(labelbody);
                    row.add(lblID);
                    row.add(CheckedCheckbox);
                    if(item.getElementsByTagName("FlagStatus").item(0).text == 0){
                        row.backgroundColor = '#ffffff';
                    }
                    else{
                        row.backgroundColor = '#cccccc';
                    }
                    data[x++] = row;
                    row.url = "maildetails.js";
                    row.title = ival;
                    ival = parseInt(ival) + 1;              
                    row = Ti.UI.createTableViewRow({height:70,touchEnabled:true});                  
                }

    — commented 2 years ago by Abdul Rehman

  • Yuu have row = Ti.UI.createTableViewRow at the end of the code. It should be at the beginning (to create the "row" object), and then instead of data[x++] = row; try something like MyTableView.add(row);.

    If that doesn't do it, then I think it might be a bug. I too have faught with touchEnabled with regard to TableViewRows, and it doesn't seem to work as documented (and some combinations work and some don't).

    — commented 2 years ago by Shawn Lipscomb

Your Answer

Think you can help? Login to answer this question!