Android复制iPhone日期和时间选择器
看效果图
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZ2xvbmd4aW4yNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
怎样使用
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar; import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText; public class MainActivity extends Activity {
WheelMain wheelMain;
EditText txttime;
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txttime = (EditText) findViewById(R.id.txttime);
Calendar calendar = Calendar.getInstance();
txttime.setText(calendar.get(Calendar.YEAR) + "-"
+ (calendar.get(Calendar.MONTH) + 1) + "-"
+ calendar.get(Calendar.DAY_OF_MONTH) + "");
Button btnselecttime = (Button) findViewById(R.id.button1);
btnselecttime.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
LayoutInflater inflater = LayoutInflater
.from(MainActivity.this);
final View timepickerview = inflater.inflate(
R.layout.timepicker, null);
ScreenInfo screenInfo = new ScreenInfo(MainActivity.this);
wheelMain = new WheelMain(timepickerview, true);
wheelMain.screenheight = screenInfo.getHeight();
String time = txttime.getText().toString();
Calendar calendar = Calendar.getInstance();
if (JudgeDate.isDate(time, "yyyy-MM-dd")) {
try {
calendar.setTime(dateFormat.parse(time));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
int h = calendar.getTime().getHours();
int m = calendar.getTime().getMinutes();
wheelMain.initDateTimePicker(year, month, day, h, m);
new AlertDialog.Builder(MainActivity.this)
.setTitle("选择时间")
.setView(timepickerview)
.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
txttime.setText(wheelMain.getTime());
}
})
.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
}
}).show();
}
});
}
}
源代码
Android复制iPhone日期和时间选择器的更多相关文章
- $Android中日期和时间选择器的实现
创建日期或时间选择窗口需要弹出Dialog的时候,Activity类的showDialog方法已经弃用了,而推荐使用的是DialogFragment,本文总结一下其具体用法. (一)日期选择器 1.创 ...
- 日期、时间选择器(DatePicker和TimePicker)的功能与用法
DatePicker和TimePicker是两个比较易用的控件,它们都从FrameLayout派生而来,其中DatePicker供用户选择日期:而TimePicker则供用户选择时间. DatePic ...
- 转:【微信小程序常见问题】下拉框选择器设置picker属性。(包括:城市、日期和时间选择器)
1.picker写法(支持日期Date.时间Time和城市自定义) wxml文件 <picker bindchange="bindPickerChange" value=&q ...
- Android 一个漂亮的Android日期和时间选择器:DateTimePicker
DateTimePicker这个类库包含了漂亮的 DatePicker 和 TimePicker ,类似于在新 Google Agenda App中看到的. 项目主页:http://www.open- ...
- Android课程---日历选择器和时间选择器
package com.hanqi.test5; import android.os.Bundle; import android.support.annotation.IdRes; import a ...
- JS日期时间选择器
本文介绍一种日期和时间选择器的使用方法.此选择器由jqueryUI实现,支持精确到毫秒的时间选择. 此选择器项目地址为http://trentrichardson.com/examples/timep ...
- Android 仿iPhone的日期时间选择器
可选只选择日期,也可以同时选择时间 只选择日期的情况 同时选择日期和时间的情况 关键代码: findViewById(R.id.selectDateButton).setOnClickListener ...
- Android日期时间选择器实现以及自定义大小
本文主要讲两个内容:1.如何将DatePicker和TimePicker放在一个dialog里面:2.改变他们的宽度: 问题1:其实现思路就是自定义一个Dialog,然后往里面同时放入DatePick ...
- Android零基础入门第57节:日期选择器DatePicker和时间选择器TimePicker
原文:Android零基础入门第57节:日期选择器DatePicker和时间选择器TimePicker 在实际开发中,经常会遇见一些时间选择器.日期选择器.数字选择器等需求,那么从本期开始来学习And ...
随机推荐
- firefox同步数据时无响应问题
之前设置了firefox的数据同步,可以在不同电脑上,同步自己的书签等信息,感觉很方便实用,最近在点工具立即同步时,不报错,书签也没有同步,没有任何响应: 后来查了许多网上资料,都不见效,无意间看到 ...
- bzoj1497(最小割)
传送门:最大获利 题意:建立n个中转站,每个花费P[i],有m个用户,使用Ai和Bi中转站可获利Ci,问最终建立哪几个中转站使获利最大? 分析:根据最大权闭合图建图,用户群和中转站为带权的点集,用户群 ...
- 关于JVM的ClassLoader(转)
众所周知,java是编译型的语言,写的是java文件,最后运行的是class文件,class文件是运行在JVM之中的,这时候就有一个问题,JVM如何装载class文件的?是通过ClassLoader来 ...
- NEU月赛Segment Balls(线段树)
问题 D: Segment Balls 时间限制: 1 Sec 内存限制: 128 MB 提交: 253 解决: 37 题目描述 Small K has recently earn money i ...
- hyper-v 报错 0x80070569
在Windows8.1Pro版使用过程中,突然出现HYPER-V无法创建虚拟机.显示错误为: 登录失败:未授予用户在此计算机上的请求登录类型.(0x80070569). 回顾起近期通过组策略增强了系统 ...
- C#基础总结之Attribute
Attribute是什么 Attribute的中文姓名 为什么我要拿一段文字来说Attribute的中文姓名呢?答案是:因为这很重要.正所谓“名”不正,则言不顺:另外重构手法中有一种很重要的方法叫重命 ...
- SE 2014 年4月21日(一)
如图配置 网络中存在四个自治系统,设备之间要求建立BGP对等体关系,发布BGP路由,使得全网BGP路由相互通讯. 要求 1. 由于AS 200中的路由信息频繁抖动,所以AS 100 和 AS 300 ...
- Java使用反射机制优化工厂方法
我先举个例子,有一个接口People,这个接口有一个方法: package com.wjy.reflect; public interface People { public abstract voi ...
- TextView中如何支持html标签,放置图片和动作标签
TextView文本框和输入框几乎是一个正常的带界面的可交互的Android应用的基本组成 TextView主要作用是显示文本内容,其实还可以显示图片,当然有必要的话还可以为文本内容添加动作相应用户的 ...
- cocos2d-x ndk adt mac 路径配置
export PATH=/bin:/sbin:/usr/local/mysql/bin export PATH=$PATH:/Applications/MacVim-snapshot-68 expor ...