Page 1 of 1

Display Random Entry from Contacts

Posted: Fri Feb 15, 2013 7:37 pm
by Markus Jenkins

Greetings!
I want to display a button on the start screen that will pull up a random person from the contacts. Having trouble seeing how to implement it. Any suggestions?

Thanx.


Display Random Entry from Contacts

Posted: Fri Feb 15, 2013 9:50 pm
by maxkatz

Can you show us what you tried? Are you able to load the list of contacts?


Display Random Entry from Contacts

Posted: Sat Feb 16, 2013 5:13 am
by Markus Jenkins

I think I want to take the ContactService and map it to a text area or list item. But I don't want to load all of the contacts just 1 random one.


Display Random Entry from Contacts

Posted: Sat Feb 16, 2013 5:18 am
by maxkatz

I'm not sure if PhoneGap has that specific API -- to get a random contact. You can always double check http://docs.phonegap.com/.

You will probably need to load the contacts and then pick one randomly in your code.


Display Random Entry from Contacts

Posted: Mon Feb 18, 2013 6:20 pm
by Markus Jenkins

Thanks. Doesn't look like PhoneGap has the random function built in. I will need to do some more research. If anyone could point me in the right direction, I'd be appreciative. I am a beginner-intermediate level coder.

Thanks.


Display Random Entry from Contacts

Posted: Tue Feb 19, 2013 2:35 am
by maxkatz

One option is to load all contacts and then pick a random one with JavaScript.


Display Random Entry from Contacts

Posted: Wed Feb 20, 2013 8:23 pm
by Markus Jenkins

So I would want to use: contacts.find

And then maybe set up an array, and pull a random number?