设为首页 加入收藏

TOP

Android DatePicker控件的使用
2014-11-24 11:17:54 来源: 作者: 【 】 浏览:0
Tags:Android DatePicker 控件 使用

1、申明一个监听器,使用匿名内部类:


DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.
OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
System.out.println(year + ":" + monthOfYear + ":" + dayOfMonth);
}
};


2、复写Activity类的protected Dialog onCreateDialog(int id)方法


@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_PICKER_ID:
return new DatePickerDialog(this, onDateSetListener, 2011, 8, 26);
}
return null;
}


3、在需要显示日期的时候调用showDialog(DATE_PICKER_ID)方法



例子:


main.xml文件


< xml version="1.0" encoding="utf-8" >
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
/>

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android中LayoutInflater类的使用 下一篇Android学习之AutoCompleteTextVi..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何从内核协议栈到 (2025-12-27 03:19:09)
·什么是网络协议?有哪 (2025-12-27 03:19:06)
·TCP/ IP协议有哪些 (2025-12-27 03:19:03)
·怎样用 Python 写一 (2025-12-27 02:49:19)
·如何学习python数据 (2025-12-27 02:49:16)