How can we populate a Listfield in blackberry with results from a Autocomplete field using Blackberry API(JDE 5)
Asked
Active
Viewed 1,164 times
2 Answers
1
This is the code to get Contacts, returns a vector containing string array.. contact[0] is name, contact[1] is email and contact[2] is contact number..
read elements from vector and set autocompleteField:Example: http://docs.blackberry.com/en/developers/deliverables/18125/Autocomplete_text_field_1200231_11.jsp
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[3];
if (contactList.isSupportedField(BlackBerryContact.NAME)) {
String[] name = c.getStringArray(BlackBerryContact.NAME, 0);
String firstName = name[Contact.NAME_GIVEN];
String lastName = name[Contact.NAME_FAMILY];
System.out.println("this is contact..........." + firstName);
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();
}
if ((contactList.isSupportedField(BlackBerryContact.TEL)) && (c.countValues(BlackBerryContact.TEL) > 0)) {
int numValues = 0;
try {
numValues = c.countValues(BlackBerryContact.TEL);
} catch (Exception localException) {
}
String mobileNumber = "";
String homeNumber = "";
String workNumber = "";
for (int i = 0; i < numValues; ++i) {
if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK)
workNumber = c.getString(BlackBerryContact.TEL, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME)
homeNumber = c.getString(BlackBerryContact.TEL, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE)
mobileNumber = c.getString(BlackBerryContact.TEL, i);
}
if (!mobileNumber.equalsIgnoreCase(""))
contact[2] = mobileNumber.toString();
else if (!homeNumber.equalsIgnoreCase(""))
contact[2] = homeNumber.toString();
else if (!workNumber.equalsIgnoreCase(""))
contact[2] = workNumber.toString();
}
result.addElement(contact);
}
} catch (PIMException ex) {
ex.printStackTrace();
}
return result;
}

Michael B.
- 3,410
- 1
- 21
- 32

Nadhas
- 5,421
- 2
- 28
- 42
0
There's a sample app provided with the developer tools that demonstrates the use of this field. From your developer tools directory go to samples/com/rim/samples/device/ui/autocompletefielddemo and you'll see the AutoCompleteFieldDemo.java app.

Marc Novakowski
- 44,628
- 11
- 58
- 63
-
I am through with the autocompletefield part. What i am unable to do is create a list box below the autocomplete field and populate the list field with results from the autocomplete field. Any help would be appreciated – Taha Feb 12 '10 at 11:13
-
I'm not sure what you mean - the AutoCompleteField has a built-in list below the input field that shows the current results. Why do you need another list? – Marc Novakowski Feb 12 '10 at 20:12
-
Then i should be looking to customize the ListField provided with the AutoCompleteField. Any ideas how to make it look like the Contacts search interface. – Taha Feb 17 '10 at 04:58
-
customizing a Blackberry ListField has been answered at the following link http://stackoverflow.com/questions/1872160/how-to-customize-list-field-in-blackberry – Taha Feb 17 '10 at 05:00