Blackberry - 如何从 PIMItem 获取字段标签

发布于 2024-08-31 04:06:12 字数 830 浏览 6 评论 0原文

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

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

但我有 PIMItem。有一个方法 PIMItem.getPIMList() 在下面的代码中为我返回 null。 API 位于 http://www.blackberry.com/developers/docs /5.0.0api/index.html 表示“getPIMList() 获取与此项目关联的 PIMList。”下面是我试图实现的示例代码 -

// 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 

How can we get Field Labels from PIMItem. The following code is with PIMList

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

But i have PIMItem. There is a method PIMItem.getPIMList() which returns null for me in the code below. THE API at http://www.blackberry.com/developers/docs/5.0.0api/index.html says "getPIMList()
Gets the PIMList associated with this item.
" Below is sample code that i am trying to achive -

// 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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫负雪 2024-09-07 04:06:12
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();
    }
}
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();
    }
}
梦太阳 2024-09-07 04:06:12

感谢马克斯的回复。返回 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;
}

Thanks Max for the response. The returning NULL issue was problem with my code which i have rectified. I was also able to get Labels for Fields, but the loop retrieves only fields that the Contact has on his card.

I am looking to get all the 8 labels that Contact.TEL has -

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

All the 8 Labels might not be in use in for a user, For e.g a user might have WORK, WORK2, HOME, HOME2 and MOBILE. Others FAX, PAGER and OTHER might not be filled i want to get all the allowed labels and update a given number for the one that is empty.
How can we check and update the following

Contact.ATTR_PAGER, Contact.ATTR_FAX, Contact.ATTR_OTHER

Please let me know if the explanation is not clear, or some more details are required.

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文