Android tableView event : e.row.children[0].children[0] return null
Hello,
I'have a problem with Android to access to the data of a row in a tableView when I click on a row.
The structure of my table view is :
var numberOfProducts = 3;
var tableView = Ti.UI.createTableView({});
var data[];
for(var i=1; i<numberOfProducts
var row = Ti.UI.createTableViewRow({...});
var viewRow = = Ti.UI.createTableView({...});
var labelNameProduct = = Ti.UI.createLabel({...});
var labelStock = = Ti.UI.createLabel({...});
viewRow.add(labelNameProduct);
viewRow.add(labelStock);
row.add(viewRow);
data.push(row);
}
tableView.setData(data);
tableView.addeventListener('click', function(e){
e.row.children[0].children[0].text = 'computer';
e.row.children[0].children[1].text = 'stock : 2';
});
On Iphone it work perfectly but on Android I have an Error on the second "children[]" of the line :
For the first line :
TypError : Cannot read property "0" from null
For the second line :
TypError : Cannot read property "1" from null
So the compilator believe that my second chlidren is null.
Why ? Somebody has any ideas ?
Regards,
2 Answers
-
I don't know whether it's actually wise to add labels directly to a TableView, as you do with your viewRow. You should create a TableViewRow, then add labels to this row and than add this row as a whole. Maybe this already solves your issue?
-
Hello,
I find my problem : the name of my TableViewRow is "row" so when I do a "e.row.children[0]…" Android is confused and use the var "row" of the TableViewRow instead of the variable "e.row" return by the EventListener.
So I rename my TableViewRow in :
var rowTableView = Ti.UI.createTableViewRow({…});And now it works !
Thanks for your answer !
Regards,