该解决方案也适用于我:
package com.my.package;
import java.util.Calendar;
import java.util.Date;
import net.rim.device.api.i18n.SimpleDateFormat;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.DateField;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.picker.DateTimePicker;
public class MyDateManager extends VerticalFieldManager {
protected DateField dateField_ = null;
protected DateTimePicker dateTimePicker_ = null;
protected SimpleDateFormat dateFormat_ = null;
public MyDateManager() {
super(Manager.FIELD_HCENTER | Manager.FIELD_VCENTER);
dateFormat_ = new SimpleDateFormat("HH:mm");
dateField_ = new DateField("", new Date().getTime(), dateFormat_,
Field.FIELD_HCENTER | DrawStyle.HCENTER | Field.FOCUSABLE) {
protected boolean touchEvent(TouchEvent paramTouchEvent) {
if (paramTouchEvent.getEvent() == TouchEvent.CLICK) {
dateField_.setEnabled(false);
showDatePicker();
}
return super.touchEvent(paramTouchEvent);
}
protected boolean trackwheelClick(int paramInt1, int paramInt2) {
dateField_.setEnabled(false);
showDatePicker();
return super.trackwheelClick(paramInt1, paramInt2);
}
};
this.add(dateField_);
}
protected void sublayout(int width, int height) {
layoutChild(dateField_, width, height);
setPositionChild(dateField_, (width - dateField_.getWidth()) / 2,
(height - dateField_.getHeight()) / 2);
int h = dateField_.getHeight();
if (h <= 0)
h = height;
setExtent(width, h);
}
protected void showDatePicker() {
if (dateTimePicker_ == null) {
Calendar cal = Calendar.getInstance();
// HACK
String dateFormat = dateFormat_.toPattern().indexOf("H", 0) == -1 ? dateFormat_
.toPattern() : null;
String timeFormat = dateFormat_.toPattern().indexOf("H", 0) != -1 ? dateFormat_
.toPattern() : null;
dateTimePicker_ = DateTimePicker.createInstance(cal, dateFormat,
timeFormat);
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
if (dateTimePicker_.doModal()) {
dateField_.setDate(dateTimePicker_.getDateTime()
.getTime());
}
dateField_.setEnabled(true);
dateField_.setFocus();
dateTimePicker_ = null;
}
});
}
}
}