DatePicker和DatePickerDialog的使用
activity_main.xml:
<Button
android:id="@+id/showDatePickerButton"
android:text="@string/calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
MainActivity.java:
package leihu.date_and_time; import android.os.Bundle; import android.app.Activity; import android.app.DatePickerDialog; import android.app.Dialog; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.DatePicker; public class MainActivity extends Activity { private Button showDatePickerButton = null; //该常量用于标识DatePickerDialog private static final int DATE_PICKER_ID = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); showDatePickerButton = (Button)findViewById (R.id.showDatePickerButton); showDatePickerButton.setOnClickListener(new ButtonListener()); } private class ButtonListener implements OnClickListener{ @Override public void onClick(View v) { // TODO Auto-generated method stub //此方法用于显示DatePickerDialog showDialog(DATE_PICKER_ID); } } DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub System.out.println(year+"-"+monthOfYear+"—"+dayOfMonth); } }; protected Dialog onCreateDialog(int id){ switch(id){ case DATE_PICKER_ID: return new DatePickerDialog (this,onDateSetListener,2012,11,21); }
return null;
} }
DatePicker和DatePickerDialog的使用的更多相关文章
- Android--UI之DatePicker、TimePicker...
前言 这一篇博客分别讲解Android平台下,关于日期和时间的几个相关控件.包括DatePicker(日期选择控件).TimePicker(时间选择控件).DatePickerDialog(日期选择对 ...
- DatePicker和DataPickerDialog以及AutoCompleteTextView的基本使用方法
1.DatePicker和DatePickerDialog的基本使用方法: main.xml: <?xml version="1.0" encoding="utf- ...
- android内部培训视频_第三节(3)_常用控件(ViewPager、日期时间相关、ListView)
第三节(2):常用控件之ViewPager.日期时间相关.ListView 一.ViewPager 实例:结合PagerAdapter滑动切换图片 二.日期时间相关:AnalogClock\Dig ...
- Android精通教程V
前言 大家好,给大家带来Android精通教程V的概述,希望你们喜欢 前言 如果你想学习Android开发,那你就要了解Java编程,这是基础,也是重点,如果没学Java语法就先学习,再来学Andro ...
- Android开发中常用Dialog(普通弹窗&时间选择器&日历选择器)
引言 开发中,我们会有很多地方使用 Dialog 来展示一些提示信息或设置信息.如:用户提示.进度展示.时间设置.日期设置等. 下面我和大家一些学习下Android中常用的几种Dialog吧~ * 首 ...
- Android中DatePicker与TimePicker用法讲解(包括DatePickerDialog与TimePickerDialog)
实现效果:将DatePicker和TimePicker修改的日期和时间实时显示在程序标题栏上. 1.通过DatePicker和TimePicker来实现 布局为main.xml <?xml ve ...
- Xamarin中使用DatePickerDialog的相关问题
在Xamarin中在使用Datepicker的时候,一般情况下只需要在对应的按钮或其他控件的点击事件中使用如下语句即可完成: EditText etBirthday = FindViewById< ...
- 【Android自学日记】使用DatePicker以及TimePicker显示当前日期和时间
DatePicker 1.获取一个日历对象: Calendar cal=Calendar.getInstance(); 2.获取当前日期及时间: int year=cal.get(Calendar.Y ...
- DatePickerDialog、AutoCompleteTextView
DatePickerDialog选择日期,调用showDialog(int id)方法,会执行onCreateDialog方法: @Override protected Dialog onCreate ...
随机推荐
- 例题3_2 WERTYU(UVa10082)
把手放在键盘上时,稍不注意就会往右错一位.这样,输入Q会变成W,输入J会变成K等.键盘如下图所示: 输入一个错位后敲出的字符串(所有字母均大写),输出打字员本来想打出的句子.输入保证合法,即一定是错位 ...
- php学习之始于html——div布局与css控制
关于您的问题:xampp是一个集成的php开发环境,里面包含Apache,mysql等环境,主要充当一个服务器的角色, 其中有文件,数据,路径等,一个网站程序安装之后,都会有一个根目录,根目录下,有其 ...
- DOCK-SWARM
服务原理: 创建集群:建立ingress网络,网关xxxxx.xxx.xxx.1 管理节点:docker swarm init --advertise-addr 192.168.4.119 工作节点: ...
- map或者对象转换
map或者对象转换为具有相同字段的对象 List<Example> errorCodeExcelBeanList = JSONObject.parseArray(((JSONObject) ...
- 阿里云虚拟主机申请免费SSL证书并成功开通Https访问
参考文档网址 https://baijiahao.baidu.com/s?id=1628343140232374972&wfr=spider&for=pc
- wx小程序笔记
目录 p18 事件绑定1 p19 事件绑定2 btn p20+ view 相关,wxss,less,css 零基础玩转微信小程序[黑马程序员] https://www.bilibili.com/vid ...
- if条件语句!
1.if 单分支语句 if [ 条件语句 ] then 条件操作fi 例子: [root@localhost ~]# if [ 1 -eq 0 ] //如果1等 ...
- [运维] 请求 nginx 出现 502 Bad Gateway 的解决方案!
环境: 云服务器镜像 Linux CentOS 7.6 已经安装并成功配置 SSL 的 nginx 1.16.1 成功安装并且可以正常运行的 apache-tomcat-9.0.26 遇到的问题: 在 ...
- Pentaho6.1中D3可视化库的集成及数据联动的实现
1.软件环境 操作系统版本:Win 10 64位 可视化图形库:D3 Pentaho版本: biserver-ce-6.1.0.1-196 2.对D3的简单介绍 D3允许你将任意的数据绑定到文档对象模 ...
- 关于Action模型驱动无法获取属性的问题
这两天在练习ssh小项目发现action层怎都无法获取Ajax传过来的json: 1.检查表单name和action定义属性名是否一致 2.get/Set方法 3.表单和属性名的命名问题,驼峰法