Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Dynamically create labels, how?

Since we can't change the font on the tableView, I'm looking at using labels instead. However, I'm not sure how to have them dynamically created.

Here is my code that does the data, but I'm not sure where in it I would put a createLabel (and use the title for the display).

.
.
.
while (rows.isValidRow()) {
                  data.push({
                    id: rows.fieldByName('id'),
                      lat: rows.fieldByName('lat'),
                    lon: rows.fieldByName('lon'),
                    title: rows.fieldByName('caption'),

                    info: rows.fieldByName('info'),
                    hasChild: true
.
.
.
— asked November 7th 2010 by Josh Lewis
  • font
  • iphone
  • label
  • tableview
1 Comment
  • Why don't you finish the question you have already started, and provide the information requested, before asking a new one?

    — commented November 7th 2010 by Paul Dowsett

1 Answer

  • This is how I add table row with two fields and different fonts

                    var row = Ti.UI.createTableViewRow({
                        layout : 'vertical',
                        height : 'auto',
                        width : UserManager.userList.size.width - 1,
                        className : "@row"
                    });
    
                    var row_user_string = Ti.UI.createLabel({
                        text : user_string,
                        top : 5,
                        left : 15,
                        right : 5,
                        width : UserManager.userList.size.width - 1,
                        font : {
                            fontWeight : 'bold',
                            fontSize : '16px'
                        },
                        height : 25
                    });
                        row.add(row_user_string);
    
                    var row_user_email = Ti.UI.createLabel({
                        text : user_email,
                        top : 2,
                        left : 15,
                        width : UserManager.userList.size.width - 1,
                        right : 5,
                        font : {
                            fontSize : '16px'
                        },
                        height : 25
                    });
    
                    row.add(row_user_email);
    
                    // Add the row to data array
                    dataArray[i] = row;
    

    pretty straight forward

    — answered November 9th 2010 by Aaron Saunders
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.