Android 日期对话框 DatePickerDialog
程序员文章站
2022-08-02 21:38:36
private int year; private int monthOfYear; private int dayOfMonth; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(saved... ......
private int year; private int monthofyear; private int dayofmonth; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); button = (button) findviewbyid(r.id.button); calendar calendar = calendar.getinstance(); year = calendar.get(calendar.year); monthofyear = calendar.get(calendar.month); dayofmonth = calendar.get(calendar.day_of_month); button.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub datepickerdialog pickerdialog = new datepickerdialog(mainactivity.this, new ondatesetlistener() { @override public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) { // todo auto-generated method stub toast.maketext(mainactivity.this, year + "年" + monthofyear + "月" + dayofmonth + "日", 1).show(); } }, year, monthofyear, dayofmonth); pickerdialog.show(); } }); }