开发者

Titanium Table view with Switch box in android causes problem while Scrolling?

开发者 https://www.devze.com 2023-04-02 22:08 出处:网络
I Create the Table View ,each row will contain Text and checkbox loaded the row with values from Database, where i set some checkbox in default true and remaining are false, but when i scroll the chec

I Create the Table View ,each row will contain Text and checkbox loaded the row with values from Database, where i set some checkbox in default true and remaining are false, but when i scroll the checkbox are selected in default where i set it as false, while scrolling only the problem occur, i don`t know how to solve that.

This is the code i use.

i also tried instead of setting default values for checkbox , i initialized all checkbox as false, while selecting any check box on runtime and scroll down some other text box at also selected, it is occur only while scrolling , i don`t know how to solve this issues, if any one knows means help me out.

function setArray(){                
            var db = Ti.Database.install('../databases/ChecklistDB.sqlite','ChecklistDB');
            var rows = db.execute('SELECT DISTINCT category, defaultCheck FROM revcheck ORDER BY id');              
            var dataArray = [];         
            while (rows.isValidRow())
            {                   
                var bgcolor = 'black';
                var fontColor = 'white';                                    
                dataArray.push({
                    title: rows.fieldByName('category'),
                    check: rows.fieldByName('defaultCheck'),
                hasChild:true,           
                backgroundColor:bgcolor,
                color:fontColor,                    
                font:{fontSize:'12dp',fontFamily:'Helvetica Neue',fontWeight:'bold'}, 
                path:'../scripts/Contents.js'

                });
                rows.next();    
            }
            dataItems = [];
            //var checkbox=[];              
                for (var i =0; i < dataArray.length; i++) {
                var row = Titanium.UI.createTableViewRow();             
                var lblTitle = Titanium.UI.createLabel({
                text:dataArray[i].title,
                left:40                     
                });

                    var checkbox= Titanium.UI.createSwitch({
                    style:Titanium.UI.Android.SWITCH_STYLE_CHECKBOX,    
                    ret:dataArray[i].title,
                    left:0
                        }); 


                    if(checkbox.ret=='Metadata'){
                         checkbox.value = true;
                    }           
                     else{
                        checkbox.value = false;
                     }
                var button = Titanium.UI.createButton({
                image:'../images/arrows.png',
                left:270                    
                }); 
                button.addEventListener('click', function(){
                var win = Titanium.UI.createWindow({
                url:'../scripts/Contents.js',               
                fullscreen: false
                }); 
                    win.open();
                });


                row.add(lblTitle);
                row.add(checkbox);
                row.label = lblTitle;                   
                //row.checkbox = checkbox;
                row.add(button);
                row.button = button;
                row.className = 'ContentsRow';
                dataItems.push(row);


                }   
            tableview.setData(dataItems);


        }

        var tableview = Ti.UI.createTableView({
            backgroundColor:'black',
            backgroundSelectedColor:'#12A1FF',                  
            top:'2%',
            left:0,
            height:'95%',
开发者_开发知识库            width:'100%'                
        }); 

        setArray();

Thanks.

Titanium Table view with Switch box in android causes problem while Scrolling?

Titanium Table view with Switch box in android causes problem while Scrolling?


try setting the className property on the tables. also what version of the SDK are you using.

0

精彩评论

暂无评论...
验证码 换一张
取 消