Titanium Community Questions & Answer Archive

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

Change color of label on tableViewRow when tapped

I have a tableView where the rows contain labels (with black text). The selectedBackgroundColor of the rows is red, so when the user taps a rows, I'd like to change the color of the labels to white to improve readability. I'm currently using the following code:

tableView.addEventListener('touchstart', function(e) {
  e.row.children[0].color = '#fff';

tableView.addEventListener('touchend', function(e) {
  e.row.children[0].color = '#000';

It works, but it's definitely buggy. Depending on how the user taps, it might not change the color to white at all, or it might change it to white and leave it as white when the row is deselected. Also, occasionally when the user taps a row, multiple rows are highlighted.

Is this a bug, or is there a better way to achieve this?

— asked July 30th 2010 by Slim McKinsley
  • change
  • color
  • label
  • tableviewrow
  • touchend
  • touchstart
1 Comment
  • I bugged this in Lighthouse (#1428) about a month ago and it doesn't look like it's been noticed. Is there any way to get this prioritized by Appcelerator? Would love to see a fix make it into 1.5.

    — commented August 28th 2010 by Slim McKinsley

2 Answers

  • If anyone still having trouble with setting the selected color to a label in the table row.

    The solution is:

    var label = Ti.UI.createLabel({
      HighlightedColor: 'white',
      color: 'black'

    By setting a property called "HighlightedColor" to a label, the color will be used when a click event has been triggered by a table row.

    — answered May 7th 2011 by William Xue
  • +1

    — answered April 1st 2011 by Doney den Ouden
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.