Reputation: 3876
i have a table view which contain a label in each row so what i want to do is changing the label backgroundColor and color on user click
but what i get is just changing the color and the background color is changed just on user click and then go back to default color
here is my listener :
s_f_table1.addEventListener("click", function(e) {
e.source.setBackgroundColor("red");
e.source.color = "black";
console.log(e.source.id);
});
Upvotes: 0
Views: 509
Reputation: 2712
If you are using a custom layout try this:
tableView.addEventListener("click", function(e) {
var label = e.row.children[0]; // Label doesn't has to be the first child, depend on your layout.
label.color = "black";
label.backgroundColor = "red";
});
however if you have the default row style then you can setup properties as selectedBackgroundColor
, selectedColor
or selectionStyle
. See the documentation http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.TableViewRow
or you can do following:
tableView.addEventListener("click", function(e) {
e.row.color = "black";
e.row.backgroundColor = "red"; // Whole row
});
Edit: If you want to change a background color don't forget to disable selectionStyle of the row using: selectionStyle: Ti.UI.iPhone.TableViewCellSelectionStyle.NONE
Upvotes: 1