【Android】6.4 DatePickerDialog和TimePickerDialog
分类:C#、Android、VS2015;
创建日期:2016-02-08
一、简介
在Android应用中,日期选择对话框和时间选择对话框是分别提供的。
日期选择对话框(DatePickerDialog)用于选择年、月、日;
时间选择对话框(TimePickerDialog)用于选择时、分。
二、示例--Demo04DatePicker
1、运行截图

2、添加Demo04_DatePicker.axml文件
在layout文件夹下添加该文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/btnDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="选择日期" />
<TextView
android:id="@+id/textDateInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:editable="false"
android:gravity="center"
android:layout_marginBottom="20dp"
android:text="选择的日期为:" />
<Button
android:id="@+id/btnTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="选择时间" />
<TextView
android:id="@+id/textTimeInfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:editable="false"
android:gravity="center"
android:layout_marginBottom="20dp"
android:text="选择的时间为:" />
<AnalogClock
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/analogClock1" />
</LinearLayout>
3、添加Demo04DatePicker.cs文件
在SrcActivity文件夹下添加该文件。
using System;
using Android.App;
using Android.OS;
using Android.Widget; namespace ch06demos.SrcActivity
{
[Activity(Label = "Demo04DatePickerTimePicker")]
public class Demo04DatePickerDialog : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Demo04_DatePickerDialog); var date = DateTime.Now;
var hour = date.Hour;
var minute = date.Minute; var textDateInfo = FindViewById<TextView>(Resource.Id.textDateInfo);
var btnDate = FindViewById<Button>(Resource.Id.btnDate);
btnDate.Click += delegate
{
var dialog = new DatePickerDialog(this, (sender, args) =>
{
date = args.Date;
textDateInfo.Text = string.Format("选择的日期为:{0:yyyy-MM-dd}", date);
},
date.Year,
date.Month - , //Andoid的月份从0开始计数,所以要减1
date.Day);
dialog.Show();
}; var textTimeInfo = FindViewById<TextView>(Resource.Id.textTimeInfo);
var btnTime = FindViewById<Button>(Resource.Id.btnTime);
btnTime.Click += delegate
{
var dialog = new TimePickerDialog(this, (sender, args) =>
{
hour = args.HourOfDay;
minute = args.Minute;
textTimeInfo.Text = string.Format("选择的时间为:{0:00}:{1:00}", hour, minute);
}, hour, minute, true); //true:24小时制,false:12小时制
dialog.Show();
};
}
}
}
4、运行
按<F5>键调试运行。
【Android】6.4 DatePickerDialog和TimePickerDialog的更多相关文章
- Android开发之DatePickerDialog与TimePickerDialog的功能和使用方法具体解释
DatePickerDialog与TimePickerDialog的功能比較简单,使用方法也非常easy.仅仅要以下两步就可以. Ø 通过newkeyword创建DatePickerDialog.T ...
- android学习笔记19——对话框(DatePickerDialog、TimePickerDialog)
DatePickerDialog.TimePickerDialog ==> DatePickerDialog.TimePickerDialog功能.用法都比较简单,操作步骤: 1.通过new关键 ...
- Android中DatePicker与TimePicker用法讲解(包括DatePickerDialog与TimePickerDialog)
实现效果:将DatePicker和TimePicker修改的日期和时间实时显示在程序标题栏上. 1.通过DatePicker和TimePicker来实现 布局为main.xml <?xml ve ...
- 完全参照系统自带的DatePickerDialog、TimePickerDialog的源代码仿写的DateTimePickerDialog
完全参照系统自带的DatePickerDialog.TimePickerDialog的源代码仿写的DateTimePickerDialog.具有同时选择日期.时间的功能.在2.2.2.3平台,显示的效 ...
- 使用DatePickerDialog、TimePickerDialog
DatePickerDialog与TimerPicker的功能比较简单,用户也简单,只要如下两步即可. ①通过new关键字创建DatePickerDialog.TimePickerDialog实例,调 ...
- Android开发手记(9) DatePickerDialog 和 TimePickerDialog
1.DatePickerDialog 用于获取用户输入的日期信息.其原型为: public DatePickerDialog(Contex contex, DatePickerDialog.OnDa ...
- Android DatePickerDialog和TimePickerDialog显示样式
可以用DatePickerDialog显示选取日期的对话框.可以设置显示的样式 1.通过构造方法设置显示样式. 可以通过DatePickerDialog(Context context, int th ...
- Android日期时间控件DatePickerDialog和TimePickerDialog
1.DatePickerDialog 在一些万年历.日程表等APP上我们经常可以看到日期选择控件,由于很少有用户会老老实实的手工输入日期,所以该控件的作用就是为了控制用户的输入格式,在Android中 ...
- android入门 — ProgressDialog/DatePickerDialog/TimePickerDialog
这三个Dialog都是AlertDialog的子类. ①DatePickerDialog 1.创建DatePickerDialog的实例: 2.通过Calendar类获得系统时间: 3.通过DateP ...
随机推荐
- 新浪微博SSO登陆机制(转载)
原文地址: http://www.cnblogs.com/AloneSword/p/3840548.html 最近在使用sina微博时,经常性交替使用 weibo.com 和 t.sina.cm.cn ...
- Memcached 的一些用法
public interface ICache { object Get(string key); /// <summary> /// 根据 key 从缓存中读取数据 /// </s ...
- Linux用户、组帐号和权限(学习笔记九)
一.用户分类 超级用户:root 普通用户:由超级用户和管理员创建,一般只在自己的目录中有完全的权限 程序用户: 二.用户账号管理 常用命令: useradd:添加用户 userdel:删除用户 pa ...
- CMake 基本用法--写CMakeList.txt
http://techbase.kde.org/Development/Tutorials/CMake_(zh_CN) http://www.cmake.org/Wiki/CMake 这一章将从软件开 ...
- java常见错误--Access restriction: The type BASE64Encoder
Access restriction: The type BASE64Encoder is not accessible due to restrict 在Eclipse中编写Java代码时,用到了B ...
- android的download manager(1)
android 2.3中引入了Download manager.作为一个service来优化长时间下载操作的处理.Download Manager通过处理HTTP链接.监控链接的变化和系统又一次启动来 ...
- Android API之android.widget.Filterable
android.widget.Filterable 定义了一种可过滤的行为.Filterable接口通常有android.widget.Adapter来实现.接口Filterable中有个抽象方法 ...
- Fork me on GitHub
<a href="https://github.com/yadongliang"><img style="position: absolute; top ...
- HDUOJ----(4788)Hard Disk Drive
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...
- hdu1695 容斥原理 莫比乌斯反演
给定两个数b,d,问[1,b]和[1,d]区间上有多少对互质的数.(x,y)和(y,x)算一个. 对于[1,b]部分,用欧拉函数直接求.对于大于b的部分,求n在[1,b]上有多少个互质的数,用容斥原理 ...