Titanium Community Questions & Answer Archive

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

Changing the text in a lable in a view in a table row?

Suppose I have a label created from

var headerView = Ti.UI.createView({
height:'auto'
});

And I also create a view

var headerLabel = Ti.UI.createLabel({
width:'auto',
height:'auto',
text:"test", // Language
});

headerView.add(headerLabel);

And I add create a TableViewSection …

data[0] = Ti.UI.createTableViewSection({
headerView:headerView
});

And a row

var row = Ti.UI.createTableViewRow({
height:'auto'
});

And

data[0].add(row);

// create table view
var tableview = Titanium.UI.createTableView({
data:data,
backgroundColor:'transparent',
style: Titanium.UI.iPhone.TableViewStyle.GROUPED
});

How do I later change the text in the headerview label currently set as 'test'?

— asked March 31st 2010 by Peter Lum
  • change
  • header
  • label
  • table
  • text
  • view
0 Comments

3 Answers

  • Accepted Answer

    I think this might be what you're after:

    tableview.addEventListener('click', function(e)
    {
        e.section.headerView.children[0].text = 'New label';
    });
    

    There have been some repaint issues with headers though so if you don't see a change you might need to inspect headerLabel.text directly to see whether the code worked (and if so patiently wait for a repaint fix).

    — answered March 31st 2010 by James K
    permalink
    0 Comments
  • or an easier way:

    headerLabel.text = "new text";
    
    — answered March 31st 2010 by Glenn Tillemans
    permalink
    0 Comments
  • Thanks, it work but there is a repaint issues. Will see if I can find a fix.

    — answered March 31st 2010 by Peter Lum
    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.