0

纯粹从本教程(http://developer.android.com/guide/topics/ui/controls/pickers.html)开始,我可以轻松地显示选择器,但不知道如何从中获取实际值。

public static class TimePickerFragment extends DialogFragment
                        implements TimePickerDialog.OnTimeSetListener {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current time as the default values for the picker
        final Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);

        // Create a new instance of TimePickerDialog and return it
        return new TimePickerDialog(getActivity(), this, hour, minute,
                DateFormat.is24HourFormat(getActivity()));
    }

    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        // Do something with the time chosen by the user
    }
}

public void showTimePickerDialog(View v) {
    DialogFragment newFragment = new TimePickerFragment();
    newFragment.show(getSupportFragmentManager(), "timePicker");
}
4

2 回答 2

0
hour =timePicker.getCurrentHour();
minute =timePicker.getCurrentMinute();
于 2014-02-04T13:38:26.683 回答
0

public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Do something with the time chosen by the user }

此函数将具有选定的值。

您可以从TimePicker类中获得更多感兴趣的功能

于 2013-10-15T01:27:51.597 回答