Android 日期对话框DatePickerDialog
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:id="@+id/et"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false"
android:cursorVisible="false" /> <Button
android:text="日期对话框"
android:id="@+id/dateBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <Button
android:text="时间对话框"
android:id="@+id/timeBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <DigitalClock
android:text="@+id/digitalClock"
android:textSize="20dip"
android:gravity="center"
android:id="@+id/DigitalClock01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <AnalogClock
android:id="@+id/analogClock"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> </LinearLayout>
package com.example.yanlei.my; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker; public class MainActivity extends AppCompatActivity { private Button dateBtn = null;
private Button timeBtn = null;
private EditText et=null;
private final static int DATE_DIALOG = 0;
private final static int TIME_DIALOG = 1;
private Calendar c = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et=(EditText)findViewById(R.id.et);
dateBtn = (Button) findViewById(R.id.dateBtn);
timeBtn = (Button) findViewById(R.id.timeBtn);
dateBtn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
showDialog(DATE_DIALOG);
}
}); timeBtn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
showDialog(TIME_DIALOG);
}
});
} /** * 创建日期及时间选择对话框 */ @Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case DATE_DIALOG:
c = Calendar.getInstance();
dialog = new DatePickerDialog(this,new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker dp, int year,int month, int dayOfMonth) {
et.setText("您选择了:" + year + "年" + (month+1) + "月" + dayOfMonth + "日");
}
}, c.get(Calendar.YEAR), // 传入年份
c.get(Calendar.MONTH), // 传入月份
c.get(Calendar.DAY_OF_MONTH) // 传入天数
);
break;
case TIME_DIALOG:
c=Calendar.getInstance();
dialog=new TimePickerDialog(this,new TimePickerDialog.OnTimeSetListener(){
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
et.setText("您选择了:"+hourOfDay+"时"+minute+"分");
}
},
c.get(Calendar.HOUR_OF_DAY),
c.get(Calendar.MINUTE),
false
);
break;
}
return dialog;
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} return super.onOptionsItemSelected(item);
}
}
参看http://blog.csdn.net/jianghuiquan/article/details/8350468
Android 日期对话框DatePickerDialog的更多相关文章
- Android 日期对话框 DatePickerDialog
private int year; private int monthOfYear; private int dayOfMonth; @Override protected void onCreate ...
- 日期对话框(DatePickerDialog)和时间对话框(TimePickerDialog)
效果图 布局 <Button android:id="@+id/btn_date" android:text="弹出日期选择对话框" android:la ...
- Android日期对话框NumberPicker的使用方法教程
NumberPicker是Android3.0之后引入的一个控件.NumberPicker 是用于选择一组提前定义好数字的控件.比方时间hour的选择仅仅有0-23有效,则能够通过setMinValu ...
- Android时间对话框TimePickerDialog介绍
目前网上流行着很多对“时间对话框TimePickerDialog”的讲解文章,但感觉都不是很详细.这里详细对该方面的知识进行介绍,旨在帮助初学者能够快速掌握该项技术. 首先要做的是声明一个日历类的对象 ...
- Android课程---时间日期对话框
activity_ui2.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- 9.Android之日期对话框DatePicker控件学习
设置日期对话框在手机经常用到,今天来学习下. 首先设置好布局文件:如图 xml对应代码 <?xml version="1.0" encoding="utf-8&qu ...
- Android 中日期对话框的应用
import java.util.Calendar; import android.widget.DatePicker; import android.app.DatePickerDialog; // ...
- Android日期时间控件DatePickerDialog和TimePickerDialog
1.DatePickerDialog 在一些万年历.日程表等APP上我们经常可以看到日期选择控件,由于很少有用户会老老实实的手工输入日期,所以该控件的作用就是为了控制用户的输入格式,在Android中 ...
- Android(对话框)
一.消息对话框 所谓的消息对话框,就是说当你点击按钮弹框,它会弹出一个消息提示你,消息对话框有相应的确定.取消.其他按钮,比如下方: 代码: //消息提示框 public void testOne(V ...
随机推荐
- Dataflow编程模型和spark streaming结合
Dataflow编程模型和spark streaming结合 主要介绍一下Dataflow编程模型的基本思想,后面再简单比较一下Spark streaming的编程模型 == 是什么 == 为用户提 ...
- OpenStack之虚机热迁移代码解析
OpenStack之虚机热迁移代码解析 话说虚机迁移分为冷迁移以及热迁移,所谓热迁移用度娘的话说即是:热迁移(Live Migration,又叫动态迁移.实时迁移),即虚机保存/恢复(Save/Res ...
- 【Scramble String】cpp
题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...
- alert(1) to win部分解题
XSS在线习题分析 (https://alf.nu/alert1) 1. Warmup function escape(s) { return '<script>console.log(& ...
- Python Unicode与中文处理
转自:http://blog.csdn.net/dao123mao/article/details/5396497 python中的unicode是让人很困惑.比较难以理解的问题,本文力求彻底解决这些 ...
- Recommender System
推荐系统我们都很熟悉,淘宝推荐用户可能感兴趣的产品,搜索引擎帮助用户发现可能感兴趣的东西,这些都是推荐系统的内容.接下来讲述一个电影推荐的项目. Netflix 电影推荐系统 这个项目是使用的Netf ...
- 在数组中寻找出现次数大于N/K的数
给定一个int[]数组,给定一个整数k,打印所有出现次数大于N/k的数,没有的话,给出提示信息. === 核心思想:一次在数组中删除K个不同的数,不停的删除,直到剩下的数的种类不足K就停止删除,那么如 ...
- mysql中游标的使用案例详解(学习笔记)(转)
1.游标是啥玩意?简单的说:游标(cursor)就是游动的标识,啥意思呢,通俗的这么说,一条sql取出对应n条结果资源的接口/句柄,就是游标,沿着游标可以一次取出一行.我给大家准备一张图: 2.怎么使 ...
- GDOI2018前夕 错误总结
算法易错点 $FFT$ 1.注意精度,以及是否取整 2.注意$complex$类不要写错,复数乘法是这样的: complex operator *(const complex &b){retu ...
- nodeJS(2)深了解: nodeJS 项目架构详解(app.js + Express + Http)
简略了解:nodeJS 深了解(1): Node.js + Express 构建网站预备知识 环境: 环境: win7 + nodeJS 版本(node): 新建 nodeJS 项目: 名称为: te ...