Dear folk I don't understand why, a tableview with custom row doesn't have onclick effect (when click on the row the background of that row change for a short time), while a tableview without custom row does have this effect, why?
here is the code of these two tableview that I use, with custom row, I notice that the row does has a flash on the label text, but the background color doesn't change a bit.
var tvs = Ti.UI.createTableViewSection({ headerTitle:'Profile' }); for(i=0;i<3;i++) { var row=Ti.UI.createTableViewRow({ height: 80, className: 'group' }); var image=Ti.UI.createImageView({ left:8, width:48, image:'/images/Circle-48.png' }); var label=Ti.UI.createLabel({ left:65, width:313 , text:'Profile '+i }); var sw = Titanium.UI.createSwitch({ right:8, }); sw.addEventListener('click',function(e){ alert(label.text); }); row.add(image); row.add(label); row.add(sw); tvs.add(row); } var tableView = Titanium.UI.createTableView({ data:[tvs] }); tableView.addEventListener("click",function(e){});where the non custom row will change it background color when click on it.
// Create a TableView. var aTableView = Ti.UI.createTableView(); // Populate the TableView data. var data = [ {title:'Row 1', hasChild:true, color:'red', header:'First'}, {title:'Row 2', hasDetail:true, color:'green'}, {title:'Row 3', hasCheck:true, color:'blue', header:'Second'}, {title:'Row 4', color:'orange'} ]; aTableView.setData(data); // Listen for click events. aTableView.addEventListener('click', function(e) { alert('title: \'' + e.row.title + '\', section: \'' + e.section.headerTitle + '\', index: ' + e.index); });anyone has any idea how to turn that effect back with custom row tableview much appreciate
3 Answers
Hi Jackie,
Try this code that may help you.Best luck
tableView.addEventListener("click", function(e) { e.rowData.backgroundColor = 'blue'; setTimeout(function(evt) { e.rowData.backgroundColor = "transparent"; }, 500); });
Check http://myscribles.in/tableview-row-check-in-appcelerator/ .there it is explained how clicks are managed in appcelerator
if I remove the switch which is
var sw = Titanium.UI.createSwitch({ right:8, }); row.add(sw);the onclick effect will back on, it seem that when adding button or switch, which also has this onclick effect, will case the row lose it, i also notice that the row click event will also lose, which will be taken by the label, meaning the row click event only fire when I click on the label, is this some kind bug?
because I want this effect, I've to remove the switch and replace it with a image which looks like a switch, although that doesn't solve the problem, as the effect will only show if I click on the row empty space, if I click on the label or image it's still nothing. but the good thing is click event is work properly (thank god).
I choose Titanium because I thought it will save my time, now it seem that I'm spending more time on go around these bugs or things that it will be but it doesn't, and I've find a way perhaps spend more time to ask people if they've the similar problem, or try this try that........man it's not free nor quick at all.
Your Answer
Think you can help? Login to answer this question!