Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked May 11th 2010 by Bruno Mandolesi
  • call
  • phone
  • tableview
0 Comments

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

    — answered May 11th 2010 by Angus Peart
    permalink
    0 Comments
  • 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);

    — answered May 11th 2010 by Bruno Mandolesi
    permalink
    0 Comments
  • Hi Angus!

    Great, thank you for the detailed and quick answer ;-)

    cheers, bruno

    — answered May 11th 2010 by Bruno Mandolesi
    permalink
    0 Comments
  • 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);
    
    — answered May 11th 2010 by Angus Peart
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.