Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 3
Registered: ‎06-18-2009
My Device: Not Specified

Having the user select a contact

Hey so I am making a program and I could do either two things at one point, I could:

 

a.) have the user enter a person's phone number -or-

b.) have the user pick a contact from their contact list and then grab the number myself.

 

I've been reading all sorts of different stuff in the JDE about different contact types, and their fields and such.  I am pretty sure once the user selects the contact I would be able to get the phone number from that information.

 

But how do I setup a good way to select contacts?  I'm thinking something like what is on the storm, when you pop open an email or SMS to make, you just start typing and it shows a list of contacts that fit what you have typed, is there any way to do something similar to this?

 

Or even a thing where at the point I need the number, perhaps I just change the entire screen to a contact list, and they can pick "One time entry" or select a contact, but again, I do not know how to do this.

 

How do you grab all the contacts at once that someone has and put them on the screen in a neat and not sloppy way?

 

Any advice would be great.

 

Thanks,

 

Mark

 

P.S. I am using Blackberry JDE 4.7 and I use a storm which is basically what I am writing things for.

Developer
Posts: 170
Registered: ‎01-17-2009
My Device: 9630

Re: Having the user select a contact

Have you seen the BlackBerryContactList API?
New Developer
Posts: 3
Registered: ‎06-18-2009
My Device: Not Specified

Re: Having the user select a contact

Wow thanks for the quick response.

 

I had stumbled upon that at one point but was unsure if that is what I needed.

 

Have you ever used it, like what does it look like?  It was called a list so I didn't know what it looked like when displayed on the screen.  Does it sort of match up with what I was describing I was trying to do?

 

Thanks,

 

Mark

Developer
Posts: 30
Registered: ‎05-07-2009
My Device: Not Specified

Re: Having the user select a contact

[ Edited ]
I think net.rim.blackberry.api.pdap.BlackBerryContactList.choose() is exactly what you're looking for. The javadocs for this method read "Launches the address book so that the user can pick an address" and it returns "PIMItem for the Contact or BlackBerryContactGroup selected by the user; returns null if user did not make a selection". See http://www.blackberry.com/developers/docs/5.0.0api/net/rim/blackberry/api/pdap/BlackBerryContactList...()
Message Edited by cream8tor on 07-20-2009 11:25 AM
Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Having the user select a contact

it is the correct method, indeed.
just be aware of it returning contacts that may not match your criteria, without a number or mailaddress etc.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Having the user select a contact

Hey guys,

 

Sometimes in a users phone number field there are parenthese added along with dashes and sometimes there is not, this throws off opening connections for sms and such. Do you know if the extra characters are always added? Or should we clean the strings of those characters? Seems like a pain to not just be able to access the phone number in its pure form.

Like all of my posts
Developer
Posts: 30
Registered: ‎05-07-2009
My Device: Not Specified

Re: Having the user select a contact

I think you're stuck cleaning up the phone number yourself.  I don't know of any classes in the API that provide this functionality.  To get the "pure" form just remove any characters that when specified to java.lang.Character.isDigit() return false.  For example:

 

 

public static String cleanPhoneNumber(String value) { if (value != null) { StringBuffer sb = new StringBuffer(value.length()); for (int i=0; i<value.length(); i++) { char c = value.charAt(i); if (Character.isDigit(c)) { sb.append(c); } } value = sb.toString(); } return value; }

 

 

 

Highlighted
Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Having the user select a contact

Thanks, I thought thats what I was stuck with. Its interesting that when you add a new contact it sometimes auto adds those formatting pieces to it but sometimes I feel like it doesnt. Anyways, appreciate the help.
Like all of my posts