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
Developer
Posts: 15
Registered: ‎10-23-2008
My Device: Not Specified
Accepted Solution

problem with retrieving contact from contact list

Hi guys, i've written an application that opens the address book and the user is able to choose a contact. the problem is, im able to select a contact as long as the contact has an email or PIN number. if the contact desnt have either of those then i cant get his details. instead it shows the contact details. heres my code: private void showAddressBook() { try { BlackBerryContactList contacts = (BlackBerryContactList)BlackBerryPIM.getInstance().openPIMList(BlackBerryPIM.CONTACT_LIST, BlackBerryPIM.READ_WRITE); BlackBerryContact contact = (BlackBerryContact)contacts.choose(null, BlackBerryContactList.AddressTypes.PIN,false); String mobileNumber = ""; int numValues = 0; numValues = contact.countValues(BlackBerryContact.TEL); for (int i = 0; i numValues; i++) { if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) { mobileNumber = contact.getString(BlackBerryContact.TEL, i); break; } } //phoneNumber is a BasicEditField phoneNumber.setText(mobileNumber); } catch (PIMException ex) { ex.printStackTrace(); } } what I need to do is: 1. open the address book 2. click on a contact 3. set the contact mobile number to a BasicEditField. all help appreciated
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem with retrieving contact from contact list

i am not able to read your unformatted code but i would suggest that you use the choose method without parameters.

BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
blackberryContact = (BlackBerryContact) list.choose();
list.close();
----------------------------------------------------------
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: 15
Registered: ‎10-23-2008
My Device: Not Specified

Re: problem with retrieving contact from contact list

private void showAddressBook() { try { BlackBerryContactList contacts = (BlackBerryContactList)BlackBerryPIM.getInstance().openPIMList(BlackBerryPIM.CONTACT_LIST, BlackBerryPIM.READ_WRITE); BlackBerryContact contact = (BlackBerryContact)contacts.choose(null, BlackBerryContactList.AddressTypes.EMAIL,true); String mobileNumber = ""; int numValues = 0; numValues = contact.countValues(BlackBerryContact.TEL); for (int i = 0; i < numValues; i++) { if (contact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) { mobileNumber = contact.getString(BlackBerryContact.TEL, i); break; } } phoneNumber.setText(mobileNumber); } catch (PIMException ex) { ex.printStackTrace(); } }

 

sorry for the unformatted first post.
Developer
Posts: 15
Registered: ‎10-23-2008
My Device: Not Specified

Re: problem with retrieving contact from contact list

thanks simon! it worked.. :manvery-happy:
Developer
Posts: 117
Registered: ‎02-12-2009
My Device: Not Specified

Re: problem with retrieving contact from contact list

Hi,

 

I have a contact which has three email IDs, When i invoke Contact List, list of contacts is displayed, and user can click on Contact, but user is not prompted to select the email ID.

 

I am using same code suggested by you.

 

 

BlackBerryContactList list = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE); BlackBerryContact blackberryContact = (BlackBerryContact) list.choose(); list.close();

Thanks in advance,

Sandeep

 

 

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem with retrieving contact from contact list

the contact contains all three mail addresses. it is up to you to show the user a selection popup.
----------------------------------------------------------
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: 117
Registered: ‎02-12-2009
My Device: Not Specified

Re: problem with retrieving contact from contact list

Hi Simon,

 

Thanks for quick reply. So we have to handle this similar to one mentioned by dinu_hasith above using for loop.

 

One more quick question. When we invoke contact we are able to select only one contact. Is there possiblility to selecting mutiple contacts together?

 

Best regards,

Sandeep

Highlighted
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: problem with retrieving contact from contact list

no, this is not possible. you would have to create your own UI for that, storing the addressbook in an own data structure.
----------------------------------------------------------
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