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();
}
网友评论