Android中文API (60) —— DatePicker.OnDateChangedListener
前言
本章内容是android.widget.DatePicker.OnDateChangedListener,版本为Android 2.3 r1,翻译来自"cnmahj",欢迎大家访问他的博客:http://p.toolib.com/step,再次感谢"cnmahj"!欢迎你一起参与Android API 的中文翻译,联系我over140@gmail.com。
声明
欢迎转载,但请保留文章原始出处:)
Android中文翻译组:http://code.taobao.org/project/view/404/
正文
一、结构
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