【问题标题】:how to use PIM lists properly in J2ME?如何在 J2ME 中正确使用 PIM 列表?
【发布时间】:2011-03-16 05:17:22
【问题描述】:

检查是否支持 PIM 字符串数组的正确方法是什么?

我可以使用吗:

if (MyContactList.isSupportedField(Contact.ADDR)){...}

或者我会更好地检查:

if (MyContactList.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_STREET))

或两者兼而有之?

以下是我的问题代码:

if (MyContactList.isSupportedField(Contact.ADDR)) {
//...
//...
String[] AaddressLines = CurrentContact.getStringArray(Contact.ADDR, 0);;
}

如果我注释掉“if”块并不重要,它总是会崩溃。我能看到的唯一解决方法是完全忽略地址,请帮忙。

【问题讨论】:

    标签: java-me contacts jsr75 pim


    【解决方案1】:

    这样做的更好方法。它对我来说工作正常。请参阅此示例,

    String[] lists = pim.listPIMLists(PIM.CONTACT_LIST);
    ContactList clist =  (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, lists[index]);
    Enumeration contacts = clist.items();
    while (contacts.hasMoreElements()) {
    
    Contact c = (Contact) contacts.nextElement(); 
    int[] fields = clist.getSupportedFields();
    for (int count = 0; count < fields.length; count++) {
    int value = fields[count];
    // do smething
    
    if (value == Contact.ADDR && c.countValues(Contact.ADDR) > 0) {
    String[] addr = c.getStringArray(Contact.ADDR, 0);
    ...
    ...
      }
     }
    }
    

    【讨论】:

      【解决方案2】:

      即使 isSupportedField(Contact.NAME) 返回 true,我也无法在设备上获取 Contact.NAME。然后我必须通过调用来获取 Contact.NAME 的各个字段

      String[] Names = ContactObj.getStringArray(Contact.NAME, 0);

      当你连接 Names 数组中的所有元素时,你会得到联系人姓名。这适用于所有设备。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多