41
4: Using tasks
Change task information.
1.
To replace an existing value with a new value, invoke the appropriate set method, such as
setString()
.
2. To determine if a value is already set for the field, invoke
countValues()
.
3. To change an existing value, use the corresponding
set()
method.
4. Create code to manage a
FieldFullException
which a method such as
addString()
throws when a value already exists.
if (task.countValues(ToDo.SUMMARY) > 0) {
task.setString(ToDo.SUMMARY, 0, ToDo.ATTR_NONE, "Review notes");
}
Save a task.
1.
Before you commit your changes, to determine whether any task fields have changed since the
task was last saved, invoke
isModified()
2. Invoke
commit()
.
if(task.isModified()) {
task.commit();
}
Retrieve task information.
1.
To retrieve an enumeration, invoke
PIMList.items()
on the task list.
ToDoList todoList = (ToDoList)PIM.getInstance().openToDoList(
PIM.TODO_LIST, PIM.READ_ONLY);
Enumeration enum = todoList.items();
2. To retrieve an array of IDs for fields that have data for a particular
ToDo
item, invoke
PIMItem.getFields()
.
3. To retrieve the field values, invoke
PIMItem.getString().
while (enum.hasMoreElements()) {
ToDo task = (ToDo)enum.nextElement();
int[] fieldIds = task.getFields();
int id;
for(int index = 0; index < fieldIds.length; ++index) {
id = fieldIds[index];
if(task.getPIMList().getFieldDataType(id) == STRING) {
for(int j=0; j < task.countValues(id); ++j) {
String value = task.getString(id, j);
System.out.println(task.getFieldLable(id) + "=" + value);
}
}
}
}
Task
Steps
Summary of Contents for JAVA DEVELOPMENT ENVIRONMENT - - DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE
Page 4: ......
Page 7: ......
Page 10: ...10 BlackBerry Device Applications Integration Guide...
Page 12: ...12 BlackBerry Device Applications Integration Guide...
Page 50: ...50 BlackBerry Device Applications Integration Guide...
Page 56: ...56 BlackBerry Device Applications Integration Guide...
Page 65: ......
Page 66: ...2008 Research In Motion Limited Published in Canada...