如何打开日期选择器对话框?
How to open date picker dialog?
如何打开日期选择器对话框?
我尝试使用此代码,但这没有任何作用。我相信它已被弃用,但我还没有找到解决方案。
mDOB.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// get month, year and day
}
}
并使用此调用此对话框...
new DatePickerFragment().show(getFragmentManager(), "datepicker");
如何打开日期选择器对话框?
我尝试使用此代码,但这没有任何作用。我相信它已被弃用,但我还没有找到解决方案。
mDOB.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// get month, year and day
}
}
并使用此调用此对话框...
new DatePickerFragment().show(getFragmentManager(), "datepicker");