Quantcast
Viewing all articles
Browse latest Browse all 8068

Button background Image not changing on click

In titanium 3.1.0 everything was working fine. When I upgraded to titanium 3.1.2, with exactly the same code, the background image of a button is not changing in the click event.

My Code:

Checkbox.js

function Checkbox(on,off,value)
 {
    var checkbox = Ti.UI.createButton({
        title : '',
        width : '20dp',
        height : '20dp',
        backgroundImage : value? '/checkbox_on.png': '/checkbox_off.png',
        color : '#fff',
        font : {
            fontSize : 25,
            fontWeight : 'bold'
        },
        value : value //value is a custom property in this casehere.
    });
 
    //Attach some simple on/off actions
    checkbox.on = function() {
        this.backgroundImage = '/checkbox_on.png';
        this.title = '\u2713';
        this.value = true;
        if(on)on();
 
        Ti.API.info(this+" : "+JSON.stringify(this));
    };
 
    checkbox.off = function() {
        this.backgroundImage = '/checkbox_off.png';
        this.title = '';
        this.value = false;
        if(off)off();
 
 
        Ti.API.info(this+" : "+JSON.stringify(this));
    };
 
    return checkbox;
};
 
module.exports = Checkbox;
Where I create checkboxes in a table view:
var chkBoxes=[];
 
    for (var n = 0; n < poll.pollOptions.length;)
    {
        var option = poll.pollOptions[n];
        var row = Ti.UI.createTableViewRow(
        {
            pollOptionId : option.pollOptionId,
            selectedBackgroundColor:'Transparent',
            opacity : 1.0,
            height : Ti.UI.SIZE,
            width: '100%',
            className: 'row',
            objName: 'row',
            layout: "horizontal"
        });
 
 
        for (var vs = 1; vs < 3; vs++) {
            option = poll.pollOptions[n];
            if (!option) {
                break;
            }
 
            var chk = new Checkbox(null,null);
            chk.top = '3dp';
            chk.left = '3dp';
            chk._btnId=n;
            chk._chkBtnId=n;
            chk._pollOption= option;
            chkBoxes.push(chk);
 
 
 
            var rowView = Ti.UI.createView({
                height : Ti.UI.SIZE,
                width : '45%',
                right: vs == 1 ? '2%':'0%',
                objName : 'wrapperView',
                rowID : n,
                _pollOption: option,
                _chkBtnId:chk._btnId,
                top: '0',
                backgroundImage:'/poll_option.png'
            });
 
            rowView.addEventListener("click", function(e) {
                    for(var myInd = 0;myInd < chkBoxes.length; myInd++)
                    {
                        Ti.API.info('Button ID:'+e.source._chkBtnId);
                        if(chkBoxes[myInd]._btnId!=e.source._chkBtnId)
                        {
                            Ti.API.info('Turning off Button ID '+chkBoxes[myInd]._btnId);
                            chkBoxes[myInd].off();
                        }
                        else
                        {
                            Ti.API.info('Turning on Button ID '+chkBoxes[myInd]._btnId);
                            selectedOption=e.source._pollOption;
                            chkBoxes[myInd].on();
                        }
                    }
            });
 
            rowView.add(chk);
            rowView.add(optionCaption);
            rowView.add(optionText);
 
            row.add(rowView);
 
            n++;
        }
 
        data.push(row);
    }

Viewing all articles
Browse latest Browse all 8068

Trending Articles