How to create checkbox in Titanium?


In iOs there is no checkbox options. For that we have to create it by your own.

In the top of view declare both variable:

var checkboxSelected=0; //Not selected.
var checkboxImage;

Create a button as follows:

if (checkboxSelected==1) {
    checkboxImage=’/image/checkboxYes.png’;

//Add both checkboxYes.png and checkboxNo.png in the directory of the project.
    
}else{
    checkboxImage=’/image/checkboxNo.png’;
}

var checkboxBtn=Titanium.UI.createButton({
    top:228,
    height:12,
    left:30,
    width:11,
    image:checkboxImage,
    
});
yourView.add(checkboxBtn);

checkboxBtn.addEventListener(‘click’,function(e){
    if (checkboxSelected==1) {
        checkboxSelected=0;
    checkboxBtn.image=’/image/checkboxNo.png’;
        //alert(checkboxSelected);
        alert(‘Please select checkbox.’);
    }else{
        checkboxSelected=1;
        checkboxBtn.image=’/image/checkboxYes.png’;
        //alert(checkboxSelected);
        alert(‘You Have selected the checkbox..’);
    }
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s