Java Reference
In-Depth Information
ContactList contList = (ContactList)
PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
Contact ct = list.createContact();
String [] name = new String[contList.stringArraySize(Contact.NAME)];
name[Contact.NAME_GIVEN] = "Joe";
name[Contact.NAME_FAMILY] = "Tanner";
ct.addStringArray(Contact.NAME,Contact.ATTR_NONE , name);
ct.commit();
Note the use of the stringArraySize() method in the preceding code; this method is part
of the ContactList interface that can be used to obtain the (fixed) array size of string array
typed field. The method has the following signature:
public int stringArraySize(int stringArrayField)
Modifying Field Values
To change the value of the fields in an existing item, you can use any of the type-specific
methods on a Contact :
public void setBinary(int field, int index, int attributes, byte[] value,
int offset, int length)
public void setDate(int field, int index, int attributes, long value)
public void setInt(int field, int index, int attributes, int value)
public void setString(int field, int index, int attributes, String value)
public void setBoolean(int field, int index, int attributes, boolean value)
public void setStringArray(int field, int index, int attributes, String [] value)
Note that every method in the preceding list requires an index to specify the field value to
set in the case of fields with multiple values. Most fields are single valued, and using 0 as an
index will suffice.
You can determine if any fields in an item has been modified by calling
public boolean isModified()
Any change you make to the field values in the contact will be persisted to persistent
storage when you call the commit() method.
Removing Contacts
To remove a Contact , you will need to get a reference to the Contact to be removed. This can be
done by iterating through the Enumeration returned from an items() method call (see the earlier
section “Obtaining Items from a PIM List”). Once you have a reference to the Contact to be
removed, call the removeContact() method on the ContactList interface:
public void removeContact(Contact contact) throws PIMException
There is no method to remove all items from a list. You will need to iterate through the
Enumeration and remove each one individually.
Search WWH ::




Custom Search