在Titanium中创建复选框 [英] Create a CheckBox in Titanium

查看:151
本文介绍了在Titanium中创建复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有复选框的列表,我想使用 FOR LOOP 创建。

I have List of Checkboxes which i want to create using FOR LOOP.

我有以下类型的数据。

Value 1  --> checkbox image
Value 2  -->
Value 3  -->
.
.
.
Value 15 --> checkbox Image

我使用下面的代码,但没有得到它将如何工作?是正确的代码

I am using following code for that but not getting how will it work??? Is it correct code??

var chkArray = ['Value 1', 'Value 2', 'Value 3', 'Value 4', 'Value 5', 'Value 6', 'Value 7', 'Value 8', 'Value 9', 'Value 10'];

AssessmentArray = function createChkBx() {
    var chkBx = [];
    for(var i in chkArray) {
        var t = 80;
        var checkbox = Ti.UI.createSwitch({
            style : Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
            title : chkArray[i],
            value : true,
            left : '20dp',
            top : t + 30,
            height : 25,
            width : 'auto'
        });
        checkbox.addEventListener("change", function(e) {
            Ti.API.info("The checkbox has been set to " + e.value);
        });
        chkBx.push(checkbox);   
    }
    return chkBx;
}


var assessData = new AssessmentArray();

现在应该如何将它添加到我的窗口 ???这是专门为Android ...

Now how should I add this to my Window??? This is specifically for Android only...

推荐答案

var AssessmentArray = function()
{

     function AssessmentArray ()
     {

        //Pass the parent view inside which u want to add the check boxes and teh values as array 
        //gap or the distance between two checkboxes
        this.addCheckBoxes = function(window, values, gap)
        {
            var t = 0;
            var chkBx = [];
            var i = 0;
            for(i = 0; i < values.length; i++) {

                var checkbox = Ti.UI.createSwitch({
                    style : Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
                    title : chkArray[i],
                    value : true,
                    left : '20dp',
                    top : i * gap,
                    height : 25,
                    width : 'auto'
                });
                checkbox.addEventListener("change", function(e) {
                    Ti.API.info("The checkbox has been set to " + e.value);
                });
                win.add(checkbox);
                chkBx.push(checkbox);
            }
            return chkBx;
        }



     }

    return AssessmentArray;
}();

var ass = new AssessmentArray();
ass.addCheckBoxes(Ti.UI.createWindow(), ['Value 1', 'Value 2', 'Value 3', 'Value 4', 'Value 5', 'Value 6'], 50);




尝试这样的操作。

try some thing like this.

这篇关于在Titanium中创建复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆