1

我们如何从 PIMItem 获取字段标签。以下代码与 PIMList

String label = pimList.getAttributeLabel(
    blackBerryContact.getAttributes(Contact.TEL, i));

但我有 PIMItem。在下面的代码中有一个PIMItem.getPIMList()为我返回 null 的方法。http://www.blackberry.com/developers/docs/5.0.0api/index.html上的 API说“ getPIMList() Gets the PIMList associated with this item.”下面是我试图实现的示例代码 -

// Load the address Book and allow the user to select a contact
BlackBerryContactList contactList = (BlackBerryContactList) 
    PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY);
PIMItem userSelectedContact = contactList.choose();
// Now get the Field labels for contact numbers for userSelectedContact 
4

2 回答 2

1

感谢马克斯的回复。返回的 NULL 问题是我已纠正的代码问题。我还能够获得字段标签,但循环只检索联系人在他的卡上的字段。

我正在寻找 Contact.TEL 拥有的所有 8 个标签 -

Int maxAllowed = contactList.maxValues(Contact.TEL); // Gives me 8 

所有 8 个标签可能都没有为用户使用,例如,用户可能有 WORK、WORK2、HOME、HOME2 和 MOBILE。其他传真、寻呼机和其他可能未填写我想获取所有允许的标签并为空的标签更新给定的编号。我们如何检查和更新以下内容

Contact.ATTR_PAGER, Contact.ATTR_FAX, Contact.ATTR_OTHER

如果解释不清楚,或者需要更多细节,请告诉我。

BlackBerryContactList contactList = (BlackBerryContactList) 
    PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE);
PIMItem pimItem = contactList.choose();
BlackBerryContact blackBerryContact = (BlackBerryContact)pimItem;
PIMList pimList = blackBerryContact.getPIMList();
// To get Labels 
int phoneCount = blackBerryContact.countValues(BlackBerryContact.TEL);
String[] phoneNumbers = new String[phoneCount];
String[] labels = new String[phoneCount];
for (int i = 0; i > phoneCount; i++) {
    String phoneNumber = blackBerryContact.getString(Contact.TEL, i);
    String label = pimList.getAttributeLabel(
        blackBerryContact.getAttributes(Contact.TEL, i));
//Add the number and label to the array.
    phoneNumbers[i] = phoneNumber;
    labels[i] = label + ":" + phoneNumber;
}
于 2010-05-06T11:34:30.347 回答
1
class Scr extends MainScreen {
    Scr() {

    }

    protected void makeMenu(Menu menu, int instance) {
        super.makeMenu(menu, instance);
        menu.add(new MenuItem("add label", 1, 1){public void run() {
            try {
                BlackBerryContactList contactList = 
                    (BlackBerryContactList) PIM.getInstance().openPIMList(
                    PIM.CONTACT_LIST, PIM.READ_ONLY);
                BlackBerryContact contact = 
                    (BlackBerryContact) contactList.choose();
                    add(new LabelField(getContactInfo(contact)));
            } catch (PIMException e) {
                e.printStackTrace();
            }

        }});
    }

    String getContactInfo(BlackBerryContact c) {
        StringBuffer result = new StringBuffer();
        result.append("Name: ");
        result.append(c.getStringArray(
                BlackBerryContact.NAME, 0)[BlackBerryContact.NAME_GIVEN]);
        result.append(" ");
        result.append(c.getStringArray(
                BlackBerryContact.NAME, 0)[BlackBerryContact.NAME_FAMILY]);
        result.append("Email: ");
        result.append("\n");
        result.append(c.getString(
                BlackBerryContact.EMAIL, BlackBerryContact.ATTR_NONE));
        return result.toString();
    }
}
于 2010-05-06T06:55:49.770 回答