Code example for TimePicker

Methods: setCurrentHoursetCurrentMinutesetIs24HourView

0
    private TimePicker mTimePicker;
 
 
    public TimeWidget(Context context, final FormEntryPrompt prompt) {
        super(context, prompt);
 
        mTimePicker = new TimePicker(getContext());
        mTimePicker.setFocusable(!prompt.isReadOnly());
        mTimePicker.setEnabled(!prompt.isReadOnly());
 
        String clockType =
            android.provider.Settings.System.getString(context.getContentResolver(),
                android.provider.Settings.System.TIME_12_24);
        if (clockType == null || clockType.equalsIgnoreCase("24")) {
            mTimePicker.setIs24HourView(true);
        } 
 
        // If there's an answer, use it. 
        if (prompt.getAnswerValue() != null) {
 
            // create a new date time from date object using default time zone 
            DateTime ldt =
                new DateTime(((Date) ((TimeData) prompt.getAnswerValue()).getValue()).getTime());
            System.out.println("retrieving:" + ldt);
 
            mTimePicker.setCurrentHour(ldt.getHourOfDay());
            mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());
 
        } else { 
            // create time widget with current time as of right now 
            clearAnswer(); 
        } 
 
        setGravity(Gravity.LEFT);
        addView(mTimePicker);
 
    } 
 
 
    /** 
     * Resets time to today. 
     */ 
    @Override 
    public void clearAnswer() { 
        DateTime ldt = new DateTime();
        mTimePicker.setCurrentHour(ldt.getHourOfDay());
        mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());
    } 
 
 
    @Override