如何使用Blackberry API使用自动填充字段的结果填充Listfield

时间:2010-02-11 11:44:36

标签: blackberry

如何使用Blackberry API(JDE 5)使用自动填充字段的结果填充黑莓中的Listfield

2 个答案:

答案 0 :(得分:1)

这是获取Contacts的代码,返回包含字符串数组的向量。 联系人[0]是姓名,联系人[1]是电子邮件,联系人[2]是联系电话..

从vector中读取元素并设置autocompleteField:示例: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;
    }

答案 1 :(得分:0)

开发人员工具提供了一个示例应用程序,用于演示此字段的使用。从您的开发人员工具目录转到samples / com / rim / samples / device / ui / autocompletefielddemo,您将看到AutoCompleteFieldDemo.java应用程序。