Android日期选择器对话框 (DatePickerDialog)
提示:以下是本篇文章正文内容,下面案例可供参考
一、使用步骤
代码如下(示例):
date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
new DatePickerDialog(AddActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
int y = year;
int m = month + 1;
int d = dayOfMonth;
date.setText(y + "-" + m + "-" + d);
}
}
, calendar.get(Calendar.YEAR)
, calendar.get(Calendar.MONTH)
, calendar.get(Calendar.DAY_OF_MONTH))
.show();
}
});
|