一、结构
public static interface DatePicker.OnDateChangedListener
直接子类
DatePickerDialog
二、概述
表明用户变更了日期的回调函数。
三、公共方法
public abstract void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth)
(译者注:当用户修改日期onDateChanged()将被调用)
参数
view 与监听器关联的视图。
year 用户设置的年。
monthOfYear 用户设置的月份(0-11),与Calendar
兼容。
dayOfMonth 用户设置的日期。
四、补充
示例代码
public
class
DatePickerDialogSampleActivity
extends
Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.main);
final Calendar calendar = Calendar.getInstance();
final int year = calendar.get(Calendar.YEAR);
final int month = calendar.get(Calendar.MONTH);
final int day = calendar.get(Calendar.DAY_OF_MONTH);
final DatePickerDialog datePickerDialog = new DatePickerDialog(
this ,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Toast.makeText(DatePickerDialogSampleActivity. this ,
String.valueOf(year) + " / " +
String.valueOf(monthOfYear + 1 ) + " / " +
String.valueOf(dayOfMonth),
Toast.LENGTH_SHORT).show();
}
},
year, month, day);
datePickerDialog.show();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.main);
final Calendar calendar = Calendar.getInstance();
final int year = calendar.get(Calendar.YEAR);
final int month = calendar.get(Calendar.MONTH);
final int day = calendar.get(Calendar.DAY_OF_MONTH);
final DatePickerDialog datePickerDialog = new DatePickerDialog(
this ,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Toast.makeText(DatePickerDialogSampleActivity. this ,
String.valueOf(year) + " / " +
String.valueOf(monthOfYear + 1 ) + " / " +
String.valueOf(dayOfMonth),
Toast.LENGTH_SHORT).show();
}
},
year, month, day);
datePickerDialog.show();
}
}
五、相关章节
Android 中文 API (20) —— DatePicker
本文转自博客园农民伯伯的博客,原文链接:Android中文API (60) —— DatePicker.OnDateChangedListener,如需转载请自行联系原博主。