Java Reference
In-Depth Information
String lastName = pimName[Contact.NAME_FAMILY];
JSR 75 does not require implementation of any of these standard fields. You should check
to see whether the field is supported by the actual API implementation before using it. You
need to use a method on the ContactList (actually PIMList , ContactList 's superinterface) to
check for field support:
public boolean isSupportedField(int field)
You can also get a list of all the supported fields using this method:
public int [] getSupportedFields()
Reading Field Values
To read the value in a field, you need to know its data type. Table 9-1 describes the data type of
all standard Contact fields. You can look up the data type for Event and ToDo from the JSR 75
Javadocs.
There are accessor methods for each data type on the Contact (actually PIMItem ) interface:
public byte [] getBinary(int field, int index)
public long getDate(int field, int index)
public int getInt(int field, int index)
public String getString(int field, int index)
public Boolean getBoolean(int field, int index)
public String [] getStringArray(int field, int index)
Each field instance can actually contain multiple values of the same type, which is why an
index is needed for the preceding methods. For example, the Contact.TEL field may have three
values—one for fax, one for work, and one for home. In this case, the three values are accessed
on a different index of the Contact.TEL field and will each have a different attribute. Attributes
are discussed in the next section.
In many cases, there is only one single field value, and using index 0 is adequate. For example,
you can get the Contact.EMAIL field from a Contact instance (called myContact ) using the
following code:
String tmpEmail = null;
if ( myContList.isSupportedField(Contact.EMAIL))
tmpEmail = myContact.getString(Contact.EMAIL, 0);
The Contact.NAME and Contact.ADDR fields are of string array types. The code to access a
subfield requires one more level of indexing. For example, to obtain the value of the last name
of a Contact , use the following:
String [] curName = myContact.getStringArrary(Contact.NAME, 0);
String lastName = curName[Contacat.NAME_FAMILY];
Search WWH ::




Custom Search