samir chauhan
samir chauhan

Reputation: 1525

problem in creating table view and table view row at runtime in Titanium?

I am working on a Android APP. In this application I have window for reports. The reports window will contain table with fields name, amount and date. This data will come from database. So in the while loop I am creating the labels and tableViewRow. But its not working and giving errors.

This is the code Iam using :

var rows = conn.execute('SELECT * FROM entries WHERE 1 order by dt desc ');  

var i = 0;  
var k = 0;  
var l = 0;  
var j = 1;  
while (rows.isValidRow())  
{  
    var repLabel[i] = Titanium.UI.createLabel({  
        text:rows.fieldByName( 'name' ),  
        left:10,  
        textAlign:'center',  
        font:{ fontSize:16,fontFamily:'helvetica',fontWeight:'bold' },  
        color:'#999'  
    });  

var repLabel[k] = Titanium.UI.createLabel({
    text:rows.fieldByName( 'amount' ),
    left:150,
    textAlign:'center',
    font:{ fontSize:16,fontFamily:'helvetica',fontWeight:'bold' },
    color:'#999'
});

var repLabel[l] = Titanium.UI.createLabel({
    text:rows.fieldByName( 'date' ),
    left:230,
    textAlign:'center',
    font:{ fontSize:16,fontFamily:'helvetica',fontWeight:'bold' },
    color:'#999'
});

var repRow[i] = Titanium.UI.createTableViewRow({
    backgroundColor:'#fff',
});
repRow[i].add( repLabel[i] );
repRow[i].add( repLabel[k] );
repRow[i].add( repLabel[l] );
data[j] = repRow[i];
rows.next();
i++;
j++;
};

Upvotes: 0

Views: 847

Answers (1)

rivenate247
rivenate247

Reputation: 2101

You can't define var repLabel[i] like that. You have have to define the array first like var repLabel = [] then access it through repLabel[i] without the var

Upvotes: 3

Related Questions