generate phone calls from tableView data
Hi,
i would like to generate a phone call from tableviewrows. But for now all i get is a call to 875…
here is the code:
var win = Titanium.UI.currentWindow;
var numberToCall ='12345';
// create table view data object
var data = [
{title:'Row 1', url:12345},
{title:'Row 2', url:(numberToCall)},
{title:'Row 3', url:numberToCall},
{title:'Row 4', url:'numberToCall'}
];
var tableview = Titanium.UI.createTableView({
data:data
});
tableview.addEventListener('click', function(e)
{
Ti.Platform.openURL('tel:+url');
});
// add table view to the window
win.add(tableview);
thank you
4 Answers
-
Accepted Answer
Hi Bruno,
I see the problem now, I am not sure why I missed it before sorry.
This:
tableview.addEventListener('click', function(e) { Ti.Platform.openURL('tel:'+url); });
Should be:
tableview.addEventListener('click', function(e) { Ti.Platform.openURL('tel:'+e.rowData.url); });
The problem is that url does not exist in the context of the click callback function, therefore you need to use the 'e' (sender) variable which is passed to the callback, to access the event sending object.
You can find more information about the event properties passed to the "click" function here: https://developer.appcelerator.com/apidoc/mobile/1.2/Titanium.UI.TableViewRow-object.html
Cheers,
Angus -
Hi Angus,
thank you, but i tried as described but then nothing happens, the row is like inactive :-(
here is the modified, simplified code again:
var win = Titanium.UI.currentWindow;
var number ='12345';
// create table view data object
var data = [
{title:'Call 12345', hasChild:true, url:'12345'},
{title:'Call variable number', hasChild:true, url:number},
];var tableview = Titanium.UI.createTableView({
data:data
});tableview.addEventListener('click', function(e)
{
Ti.Platform.openURL('tel:'+url);
});// add table view to the window
win.add(tableview); -
Hi Angus!
Great, thank you for the detailed and quick answer ;-)
cheers, bruno
-
875 = URL on the keypad :)
You are sending the telephone number "+url" or as it is being interpreted, "857"
This line:
Ti.Platform.openURL('tel:+url');
Should be:
Ti.Platform.openURL('tel:' + url);