美文网首页
时间选择对话框(年月日)

时间选择对话框(年月日)

作者: 幽兰清风 | 来源:发表于2018-01-23 15:06 被阅读8次
    private static String dateStr, mouth, day;
    
        /**
         * 选择日期对话框,日期格式为年月日;
         * 如果想要设置样式的话,在new DatePickerDialog第二个参数位置添加即可,如DatePickerDialog.THEME_DEVICE_DEFAULT_LIGHT
         * @param activity,Activity
         * @param textView,TextView
         */
        public static void showDateDialog(Activity activity, final TextView textView) {
    
            final Calendar calender = Calendar.getInstance();
            new DatePickerDialog(activity, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int
                        dayOfMonth) {
                    if (monthOfYear <= 9) {
                        mouth = "0" + (monthOfYear + 1);
                    } else {
                        mouth = String.valueOf(monthOfYear + 1);
                    }
                    if (dayOfMonth <= 9) {
                        day = "0" + dayOfMonth;
                    } else {
                        day = String.valueOf(dayOfMonth);
                    }
                    dateStr = String.valueOf(year) + "-" + mouth + "-" + day;
                    textView.setText(dateStr);
                }
            }, calender.get(Calendar.YEAR), calender.get(Calendar.MONTH),
                    calender.get(Calendar.DAY_OF_MONTH)).show();
        }
    

    相关文章

      网友评论

          本文标题:时间选择对话框(年月日)

          本文链接:https://www.haomeiwen.com/subject/otpsaxtx.html