TableView nested in View does not receive click events

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

Hello.

I have a TableView that is nested inside a View and having an issue receiving click events on the table when a selection is made. If the TableView is added directly to the window instead, the events work as expected. Unfortunately I need the TableView nested inside a View, has anyone encountered this before? Setting touchEnabled:false on the View does not seem to effect the outcome at all either.

A snippet below to illustrate the idea (shortened).

Many thanks.

var window = Ti.UI.createWindow({
    navBarHidden : true
});
 
var table = Ti.UI.createTableView();
table.setData([{title:'Test 1'},{title:'Test 2'}]);
table.addEventListener('click', clickHandler);
 
var view = Ti.UI.createView({
    touchEnabled : false
});
view.add(table);
 
window.add(view);

— asked 11 months ago by Michael Walsh
2 Comments
  • I should have included these details in the initial post (apologies).

    Titanium mobile SDK version - 2.0.2 Emulator version - Android 2.3

    — commented 11 months ago by Michael Walsh

  • An update to the issue, I managed to get the click event to capture by following a few other forum post suggestions and putting a click event handler also on the View. This listener does nothing, but the existence somehow helps as the TableView now receives click events.

    Unfortunately another issue has presented itself from this work around, being that I have a backgroundSelectedImage on each TableViewRow that seems to intermittently work depending on where the TableViewRow is clicked. Events fire no matter the location, however the background does not update unless clicked over the top of the hasChild indicator (images below to illustrate).

    ![Click in center of button](http://michael-walsh.com.au/click-01.jpg "Click in center of button") ![Click to the right of button](http://michael-walsh.com.au/click-02.jpg "Click to the right of button")

    — commented 11 months ago by Michael Walsh

2 Answers

Works fine for me. I'm assuming you really do have a clickHandler defined somewhere else?

Here's my code. I get the debug output as expected.

var window = Ti.UI.createWindow({
    navBarHidden : true
});
 
var table = Ti.UI.createTableView();
table.setData([{title:'Test 1'},{title:'Test 2'}]);
table.addEventListener('click', function (e) {
    Ti.API.debug ("click event; row.title: " + e.row.title);    
});
 
var view = Ti.UI.createView({});
view.add(table);
 
window.add(view);
 
window.open ();

— answered 11 months ago by Jason Priebe
answer permalink
2 Comments
  • Hi Jason,

    Thanks for your answer however unfortunately I am still encountering this issue. I do have a valid listener attached to the table, and can confirm this is working when NOT nested inside a View.

    I should mention that I am testing in the Android emulator.

    Many thanks.

    — commented 11 months ago by Michael Walsh

  • My best suggestion -- boil this down to a minimal, complete app.js example so that others can just copy your code into Ti Studio and see the problem first-hand. Do this for your other problem (the background problem).

    If there's some sort of android bug (certainly not out of the question), that minimal example will help get a bug filed in JIRA.

    — commented 11 months ago by Jason Priebe

Michael try this,

var _window = Ti.UI.createWindow({
    navBarHidden : true
});
 
var view = Ti.UI.createView();
 
var data = [];
var table = Ti.UI.createTableView();    
 
var row1 = Ti.UI.createTableViewRow({title:'Test 1'});
data.push(row1);
 
var row2 = Ti.UI.createTableViewRow({title:'Test 2'});
data.push(row2);
 
table.setData(data);
 
 
view.add(table);
 
table.addEventListener('click', function (e) {
 
    alert(e.row.title);    
});
 
_window.add(view);
 
_window.open ();

Your Answer

Think you can help? Login to answer this question!