Android 实现日期选择器

参考

代码如下

public class MainActivity extends Activity {

    private TextView getTime;
    private Calendar calendar;// 用来装日期的
    private DatePickerDialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getTime = (TextView) findViewById(R.id.time);
        getTime.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                calendar = Calendar.getInstance();
                dialog = new DatePickerDialog(MainActivity.this,
                        new DatePickerDialog.OnDateSetListener() {

                            @Override
                            public void onDateSet(DatePicker view, int year,
                                    int monthOfYear, int dayOfMonth) {
                                System.out.println("年-->" + year + "月-->"
                                        + monthOfYear + "日-->" + dayOfMonth);
                                getTime.setText(year + "/" + monthOfYear + "/"
                                        + dayOfMonth);
                            }
                        }, calendar.get(Calendar.YEAR), calendar
                                .get(Calendar.MONTH), calendar
                                .get(Calendar.DAY_OF_MONTH));
                dialog.show();
            }
        });

    }
}

布局就一个textview,自己写一下就可以了

上一篇:phpstorm 和web storm汉化


下一篇:vue.js+web storm安装及第一个vue.js