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
Contributor
ankurnema12
Posts: 18
Registered: ‎10-23-2012
My Device: 9500

Button field should Work as brawse Button for contact list.

[ Edited ]

How can I get contact list or phonebook list on click  on a  button field using the blackberry api? i want to import no/ contact Detail from Number list to An Edit Field..

 

Button field should Work as brawse Button for contact list.

Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Button field should Work as brawse Button for contact list.

welcome to the support forums.

you can use
http://www.blackberry.com/developers/docs/7.1.0api/net/rim/blackberry/api/pdap/BlackBerryContactList...
to select a contact from the addressbook.
----------------------------------------------------------
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
Please use plain text.
Contributor
ankurnema12
Posts: 18
Registered: ‎10-23-2012
My Device: 9500

Re: Button field should Work as brawse Button for contact list.

thanks sir... i use this one...

 

 

package Pocket;

import java.util.Enumeration;
import java.util.Vector;

import javax.microedition.pim.Contact;
import javax.microedition.pim.PIM;
import javax.microedition.pim.PIMException;

import net.rim.blackberry.api.pdap.BlackBerryContact;
import net.rim.blackberry.api.pdap.BlackBerryContactList;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

class Scr extends MainScreen
{
public Scr() {
Vector v = getContacts();
Enumeration iterator = v.elements();
while (iterator.hasMoreElements()) {
String[] contact = (String[]) iterator.nextElement();
for (int i = 0; i < contact.length; i++)
add(new LabelField(contact[i]));
}

}

private Vector getContacts() {
Vector result = new Vector();
try {
BlackBerryContactList contactList = (BlackBerryContactList) PIM
.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
Enumeration enumx = contactList.items();
while (enumx.hasMoreElements()) {
BlackBerryContact c = (BlackBerryContact) enumx.nextElement();
String[] contact = new String[2];
if (contactList.isSupportedField(BlackBerryContact.NAME)) {
String[] name = c.getStringArray(BlackBerryContact.NAME, 0);
String firstName = name[Contact.NAME_GIVEN];
String lastName = name[Contact.NAME_FAMILY];
contact[0] = firstName + " " + lastName;
}
if (contactList.isSupportedField(BlackBerryContact.EMAIL)) {
StringBuffer emails = new StringBuffer();
int emailCount = c.countValues(BlackBerryContact.EMAIL);
for (int i = 0; i < emailCount; i++) {
String email = c.getString(BlackBerryContact.EMAIL, i);
if (email != null) {
emails.append(email.trim());
emails.append("; ");
}
}
contact[1] = emails.toString();
}
result.addElement(contact);
}
} catch (PIMException ex) {
ex.printStackTrace();
}
return result;
}
}

Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Button field should Work as brawse Button for contact list.

i would not use itens() as it is horribly slow. on a BB with 1k contacts the code loop takes several minutes, and as you execute it on the event thread your application would be terminated by the system watchdog (application not responding).

if you can, use choose.
otherwise look contacts up using itemsByName.

If you really have to use the whole addressbook you would have to copy it into your own data structure to use it, a task i did not assess as worth it when i checked requirements for my application.
----------------------------------------------------------
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
Please use plain text.