I’d finished the initial prototype few days ago, but I hadn’t a chance to post my findings. Here is how it looks:
In the previous post, I talked about the AutoCompleteField. Probably this is the most complex field I’m going to use. For the notes, I’ve use an EditField, and for the Date/Time, a DateTimeField (see how clever!).
Actually, I’m not completely happy with this last choice. Having the date and time available on the main screen doesn’t seem very intuitive. The idea of having one toggle button demands that the date is chosen at the time the user clicks the button. The way I’ve done, it passes the idea that this can be done anytime.
I believe the best choice here would open a dialog window with the date/time field as soon as the user clicks the button. That way, I’d enforcing the right behavior, and keeping the code simple at the same time. The problem is that I don’t want to deal with more than one screen for now, so I’ll keep this that way and see how things go.
But one thing that I thought was very important was to block access to the fields after the user starts an activity. To make the Notes field editable or block it, I just need to user its setEditable() method. Pretty straightforward.
My problem was the AutoCompleteField and its built-in list. For some reason, the above method doesn’t apply to this field. To solve this problem, I decided to have an invisible LabelField, and when the Start button is pressed, I switch between this LabelField and the AutoCompleteField.
As far as I could find, there is no way to simply set the field invisible. You have to actually remove it from the screen. To make things worst, the components are added to the screen in a stack way, so when I remove a field, the next field will be added at the top of this stack (or bottom, depends on your point-of-view), making the new LabelField be displayed after the Start button.
To avoid that, I’ve found a nice trick: basically you can find where is the component you want to remove, and insert the new one in that position. After that, just remove the component-to-be-invisible and you’re done.
Here is a snapshot of the code which remove the AutoCompleteField and make the LabelField visible:
buttonStart.setLabel("Stop"); editNotes.setEditable(false); int x = projectListField.getIndex(); insert(projectLabelField, x); projectLabelField.setText(projectListField.getEditField().getText()); delete(projectListField);
The getIndex() method returns the object index position on Screen. Then the insert() method adds the new field at that position. Finally, the delete() removes the previous field from screen.
Important! The field is remove from the screen, but its instance is still valid. Because of that, we don’t need to recreate it using the new, as I did at the start.
If you want to check the full source so far, just drop a comment.
My next step is to add the guts for this program, first make the project list persistent and dynamic.