欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android 日期对话框 DatePickerDialog

程序员文章站 2022-04-21 16:38:14
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();
            }
        });
    }