我想像这样创建一个 DatePicker:
可能不使用外部库。首先,可能吗?现在我可以通过这种方式创建一个简单的 DatePickerDialog:
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
public EditText activity_edittext;
public DatePickerFragment(EditText edit_text) {
activity_edittext = edit_text;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
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);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
activity_edittext.setText(String.valueOf(month + 1 ) + "/" + String.valueOf(day) + "/" + String.valueOf(year));
}
}
但它显示为普通对话框而不是“时钟”。任何想法?