分类: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的更多相关文章

  1. Android开发之DatePickerDialog与TimePickerDialog的功能和使用方法具体解释

    DatePickerDialog与TimePickerDialog的功能比較简单,使用方法也非常easy.仅仅要以下两步就可以. Ø  通过newkeyword创建DatePickerDialog.T ...

  2. android学习笔记19——对话框(DatePickerDialog、TimePickerDialog)

    DatePickerDialog.TimePickerDialog ==> DatePickerDialog.TimePickerDialog功能.用法都比较简单,操作步骤: 1.通过new关键 ...

  3. Android中DatePicker与TimePicker用法讲解(包括DatePickerDialog与TimePickerDialog)

    实现效果:将DatePicker和TimePicker修改的日期和时间实时显示在程序标题栏上. 1.通过DatePicker和TimePicker来实现 布局为main.xml <?xml ve ...

  4. 完全参照系统自带的DatePickerDialog、TimePickerDialog的源代码仿写的DateTimePickerDialog

    完全参照系统自带的DatePickerDialog.TimePickerDialog的源代码仿写的DateTimePickerDialog.具有同时选择日期.时间的功能.在2.2.2.3平台,显示的效 ...

  5. 使用DatePickerDialog、TimePickerDialog

    DatePickerDialog与TimerPicker的功能比较简单,用户也简单,只要如下两步即可. ①通过new关键字创建DatePickerDialog.TimePickerDialog实例,调 ...

  6. Android开发手记(9) DatePickerDialog 和 TimePickerDialog

    1.DatePickerDialog  用于获取用户输入的日期信息.其原型为: public DatePickerDialog(Contex contex, DatePickerDialog.OnDa ...

  7. Android DatePickerDialog和TimePickerDialog显示样式

    可以用DatePickerDialog显示选取日期的对话框.可以设置显示的样式 1.通过构造方法设置显示样式. 可以通过DatePickerDialog(Context context, int th ...

  8. Android日期时间控件DatePickerDialog和TimePickerDialog

    1.DatePickerDialog 在一些万年历.日程表等APP上我们经常可以看到日期选择控件,由于很少有用户会老老实实的手工输入日期,所以该控件的作用就是为了控制用户的输入格式,在Android中 ...

  9. android入门 — ProgressDialog/DatePickerDialog/TimePickerDialog

    这三个Dialog都是AlertDialog的子类. ①DatePickerDialog 1.创建DatePickerDialog的实例: 2.通过Calendar类获得系统时间: 3.通过DateP ...

随机推荐

  1. 微信小程序开发者工具下载地址

    下载地址:https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html

  2. Adobe Dynamic Http Streaming的简单配置与实现 (FMS, HLS, HDS)

    http://blog.csdn.net/avsuper/article/details/7663879 Adobe的Http Dynamic Streaming是针对苹果的HLS方案提出基于HTTP ...

  3. 《C++游戏开发》十六 游戏中的寻路算法(二):迷宫&A*算法基础

    本系列文章由七十一雾央编写,转载请注明出处.  http://blog.csdn.net/u011371356/article/details/10289253 作者:七十一雾央 新浪微博:http: ...

  4. es6(const、let)

    首先我很好奇,明明现代浏览器支持ES6.ES7不是那么好,为何还推行? var let const 有何区别?它们之间的限制又是什么?且听我娓娓道来 1. var 和let的关系,为何推荐let? ( ...

  5. select的placeholder和分组效果

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  6. 通过导入虚拟电脑的方式还原centos

    通过oracle vm VirtualBox安装完成一台centos,然后导出虚拟电脑,再通过导入虚拟电脑的方式还原一台centos,还原的时候改一下机器名,不要选择重新初始化所有网卡mac,还原完成 ...

  7. maven Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4

      maven Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4 CreateTime--201 ...

  8. windows下编辑的shell复制到linux无法执行

    是因为格式不对 可用vim编辑器转换格式 在vim中执行命令: set ff=unix 设置打开方式为unix

  9. Linux 添加硬盘设备

    fdisk命令用于管理磁盘分区,格式为:“fdisk [磁盘名称]”. 管理Linux系统中的硬盘设备最常用的方法就当属是用fdisk命令了,这条命令提供了添加.删除.转换分区等等功能于一身的“一站式 ...

  10. JavaScript 设计模式之简介

    一.设计模式概念解读 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.无数实战代码设计经验的总结.使用设计模式是为了让系统代码可重用.可扩展.可解耦.更容易被人 ...