【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 ...
随机推荐
- Android动态设置字体颜色
步骤: 1.在values目录下的strings.xml文件中加入颜色:比方 <color name="ccc">#ccc</color> 2.假设你直接这 ...
- ZH奶酪:IBG项目工作内容
IBG项目技术概览 (HTML/CSS/JavaScript/AngularJS/PHP/MySQL): (1)后台:PHP Yii2.0 Framework (2)前端:Ionic Framewor ...
- linux下apache的使用
Linux安装配置apache http://www.cnblogs.com/fly1988happy/archive/2011/12/14/2288064.html 1.获取软件: http://h ...
- Xiuno BBS 3.0 轻论坛程序正式版发布。
github:git clone -b v3.0 https://git.oschina.net/xiuno/xiunobbs 安装包:http://bbs.xiuno.com/down/xiuno_ ...
- WinForm如何调用Web Service
参考地址 今天看了李天平关于WinForm调用Web Service的代码,我自己模仿做一个代码基本都是复制粘贴的,结果不好使.郁闷的是,又碰到那个该死的GET调用Web Service,我想肯定又是 ...
- 实现ScrollviewSupportMaxHeight
public class ScrollviewSupportMaxHeight extends ScrollView { public final int MAX_HEIGHT = 1 ...
- Android API之android.widget.Filterable
android.widget.Filterable 定义了一种可过滤的行为.Filterable接口通常有android.widget.Adapter来实现.接口Filterable中有个抽象方法 ...
- Linux 查看登录日志及登录失败用户的ip-lastb
Linux 查看登录成功的用户信息 命令: last 最新的登录记录在最前面,所以可以用 一下命令来查看. last | less 查看登录失败的用户信息 命令: lastb 查看登录日志 命令: ...
- JavaScript-关于在IE下JavaScript的Stack overflow at line错误可能的原因
1.注册表混乱使基于IE内核的浏览器无法正常显示图片尤其是png格式, 修改一下注册表(网上搜) 2.重定义了系统的触发事件名称作为自定义函数名如: onclick / onsubmit… 都是系统 ...
- MyBatis JdbcType 与Oracle、MySql数据类型对应关系详解
本文转自:http://blog.csdn.net/loongshawn/article/details/50496460 1. Mybatis JdbcType与Oracle.MySql数据类型对应 ...