【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 ...
随机推荐
- ASP.NET MVC+Bootstrap 实现短信验证
短信验证大家都已经非常熟悉了,基本上每天都在接触手机短信的验证码,比方某宝,某东购物.站点注冊,网上银行等等,都要验证我们的手机号码真实性.这样做有什么优点呢. 曾经咱们在做站点的时候.为了提高用户注 ...
- MySQL工具1:mysqladmin
每两秒显示一下MySQL的状态,一共显示5次. # mysqladmin -uroot -p -i 2 -c 5 status 查看MySQL的运行状态: #mysqladmin -uroot -p ...
- 【线程篇】stop() 和suspend()
1.为什么不推荐用 stop()和 suspend() stop这个方法将终止所有未结束的方法,包括run方法.当一个线程停止时候,他会立即释放所有他锁住对象上的锁.这会导致对象处于不一致的状态.假如 ...
- 算法导论(CLRS)答案
算法导论(CLRS)答案 Chapter Section I 1 2 p II 1 2 3 p III 1 2 p IV 1 2 3 4 p V 1 2 3 4 p VI 1 2 3 4 5 p VI ...
- exception http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed w ...
- _x和__all__(有所理解即可)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #_x和__all__(有所理解即可) #_x #不能使用from module import *导入 [注意 ...
- ls -lrt
1,按照时间升序 命令:ls -lrt 详细解释: -l use a long listing format 以长列表方式显示(详细信息方式) -t sort by modification time ...
- 雪球、牛股王这种股票类App 到底能否帮你赚到钱?
核心观点 股民这个大群体,是需要区分对待的:其中包含一小部分有自己独立判断能力的投资者和一大群没有自己判断能力(尽管他们经常觉得自己有)的普通散户. 当前的互联网证券类App,确实很难保证帮股民赚到钱 ...
- 【微信小程序】:评论、回复和删除功能 -- 2017/7/14
1.理论核心:传参->pid,评论父id需要在wxml页面传递:小程序端和WEB端不同核心:前者操纵数据,后者操纵DOM元素对象 2.不废话,直接代码:wxml <view class=& ...
- 一个PHP操作大变量的例子
By C extensions we can directly manipulate the large PHP variables, such as:GET,POST,SERVER You can ...