The sytle of the tableview, two colors

You must Login before you can answer or comment on any questions.

Hello, I seek a way to add color to my tablevieuw. Two colors, yellow, orange, yellow, orange ...

indicate two colors in my tableView and then it automatically generates my tablevieuw with my colors

Can you help me please?

thank you

4 Answers

Accepted Answer

Hello IVedia,

you can do it with using one Flag like

var win = Ti.UI.createWindow({
 
});
 
var table = Ti.UI.createTableView({
});
 
win.add(table);
 
var data = [];
var viewcolor = true;
 
for (var i = 0; i < 10; i++) {
 
    var row = Ti.UI.createTableViewRow({
        height : 40
    });
 
    if(viewcolor){
        row.backgroundColor = 'yellow' ;
    }else{
        row.backgroundColor = 'orange' ;
    }
 
    viewcolor = !viewcolor;
    data.push(row);
 
}
 
table.data = data;
 
win.open();
just try this code....

If any problem then feel free to ask again....

Best luck.

Sarfaraz Babi thank you, it works very well your code

thank you very much

Thank you delos santos Nash, but I do not use a sql database I note your source thank you too ;)

Good day to all

:)

Can you tell me how to change the color of the bottom tableview, I think the default color is 'e0e0e0'

but I would love to put eg 'ff0000'

thank you

— answered 11 months ago by IVIedia Power
answer permalink
18 Comments
  • did you mean Background of TableView ????

    — commented 11 months ago by Sarafaraz Babi

  • And one more thing , I would like to suggest you to use comment facility for the discussion not in answer.

    — commented 11 months ago by Sarafaraz Babi

  • I talk about this border in the tableview, you can see by the image

    http://data.imagup.com/12/1156664261.jpg

    — commented 11 months ago by IVIedia Power

  • Show 15 more comments

Hi, IVIedia,

if you are getting data from sql, try this on your while loop:

// make your sql query first
 
var listArray = [];
var odd = '#2d5285',
even = '#5a779e';
 
while (rows.isValidRow()) {
        var color = (id%2) ? odd:even;
 
        var lRow = Ti.UI.createTableViewRow();
        lRow.backgroundColor = color;
 
        var name = Ti.UI.createLabel({
            text: rows.fieldByName('fieldname'),
            height: 30,
            left: 20,
            font: { fontSize: 15},
            color: '#fad2c0'
        });
        lRow.add(name);
        listArray.push(lRow);
 
        rows.next();
    }

Your Answer

Think you can help? Login to answer this question!