Markus Jenkins
Posts: 0
Joined: Fri Feb 15, 2013 7:37 pm

Display Random Entry from Contacts

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Display Random Entry from Contacts

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

Markus Jenkins
Posts: 0
Joined: Fri Feb 15, 2013 7:37 pm

Display Random Entry from Contacts

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Display Random Entry from Contacts

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.

Markus Jenkins
Posts: 0
Joined: Fri Feb 15, 2013 7:37 pm

Display Random Entry from Contacts

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Display Random Entry from Contacts

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

Markus Jenkins
Posts: 0
Joined: Fri Feb 15, 2013 7:37 pm

Display Random Entry from Contacts

So I would want to use: contacts.find

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

Return to “Issues”