Android在datepicker片段对话框后显示timepicker

时间:2014-01-28 13:40:13

标签: android dialog datepicker

我正在使用here中的参考日期和时间选择器对话框 如何在datepicker对话框后调用时间选择器? 因为如果我把这条线 showTimePickerDialog(v); 进入dateSet它说非静态......

呼叫:

showDatePickerDialog(v);
showTimePickerDialog(v);

代码:

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 minuteOfDay) {
    // Do something with the time chosen by the user
    hour = hourOfDay;
    minute = minuteOfDay;
    // Log.e("Idő","" + hourOfDay +" : " + minute);
}
}

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

public static class DatePickerFragment extends DialogFragment implements
        DatePickerDialog.OnDateSetListener {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the current date as the default date in the picker
    final Calendar c = Calendar.getInstance();
    int yearPP = c.get(Calendar.YEAR);
    int monthPP = c.get(Calendar.MONTH);
    int dayPP = c.get(Calendar.DAY_OF_MONTH);

    // Create a new instance of DatePickerDialog and return it
    return new DatePickerDialog(getActivity(), this, yearPP, monthPP, dayPP);
}

public void onDateSet(DatePicker view, int yearP, int monthP, int dayP) {
    // Do something with the date chosen by the user
    year = yearP;
    month = monthP+1;
    day = dayP;         

}
}

public void showDatePickerDialog(View v) {
    DialogFragment newFragment = new DatePickerFragment();
    newFragment.show(getSupportFragmentManager(), "datePicker");
}

0 个答案:

没有答案