如何使用TimePickerFragment保存两个不同的小时

时间:2015-08-05 17:45:26

标签: java android timepicker

我使用Time Pickerfrangment要求用户开始一小时和最后一小时,所以我必须两次保存在不同的变量中。如何说:如果按下此按钮保存在变量“x”中,如果是另一个,则保存在变量“y”中。我的代码是:

公共类TimePickerFragment扩展了DialogFragment         实现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
}

}

0 个答案:

没有答案