Java Reference
In-Depth Information
getInt : Returns the contents of an integer field as an int given its field key and the
index to the n th datum of that type
getString : Returns the contents of a string field as a String given its field key and
the index to the n th datum of that type
getBoolean : Returns the contents of a boolean field as a boolean given its field key
and the index to the n th datum of that type
getStringArray : Returns the contents of a string array field as a String [] given its
field key and the index to the n th datum of that type
For example, the code shown in Listing 7-5 returns the summary of a to-do item.
Listing 7-5. Returning the Summary of a To-Do Item
ToDoList list;
ToDo item;
// fetch item using an enumeration from PIMList
if (list.isSupportedField(ToDo.SUMMARY)) {
String summary = item.getString( ToDo.SUMMARY, 0 );
// Do something with the summary
}
Each field can contain multiple entries for the same type, which is why you pass an
index to each of these accessor methods. For example, to enumerate over all phone num-
bers in a contact, you might write the code shown in Listing 7-6.
Listing 7-6. Enumerating Over Record Fields in a Contact
ContactList list;
Contact item;
int i=0;
// fetch item using an enumeration from PIMList
if (list.isSupportedField(Contact.TEL)) {
String phone;
phone = item.getString(Contact.TEL, i);
while(phone!=null) {
// Do something with the phone here.
i++;
phone = item.getString(Contact.TEL, i);
}
}
 
Search WWH ::




Custom Search