Custom Row in TableView onclick effect

You must Login before you can answer or comment on any questions.

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

— asked 1 year ago by J T
1 Comment
  • forget to mention I'm testing in android with 2.0 API

    — commented 1 year ago by J T

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);
});

— answered 1 year ago by Nitin Chavda
answer permalink
5 Comments
  • well, the row should have this effect by it nature without do additional staff, coz the non-custom row does , but thank anyway

    — commented 1 year ago by J T

  • Okey Jackie,

    In your case you added images and labels that's why your background selection of row not displayed.

    — commented 1 year ago by Nitin Chavda

  • Thanks Chavda is that mean, I can not add any of these to a row if I want to keep this effect(it work on a non-custom one with label image on it), well if this is true, then I don't see any point make this custom row.

    — commented 1 year ago by J T

  • Show 2 more comments

Check http://myscribles.in/tableview-row-check-in-appcelerator/ .there it is explained how clicks are managed in appcelerator

— answered 1 year ago by Ajai Kumar
answer permalink
1 Comment
  • thanks kumar, but that seem irrelevance to my problem

    — commented 1 year ago by J T

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.

— answered 1 year ago by J T
answer permalink
1 Comment
  • it should be not will be, but I think will is also suitable, because the word will mean you're going to do it, but it doesn't mean you do it right

    — commented 1 year ago by J T

Your Answer

Think you can help? Login to answer this question!