Android仿iPhone日期时间选择器详解
作者:DylanAndroid 发布时间:2023-09-11 04:23:37
标签:Android,iPhone,选择器
本文实例为大家分享了Android仿iPhone时间选择器的具体代码,供大家参考,具体内容如下
先看效果图
如何使用
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();
}
});
}
}
源码下载:仿iPhone日期时间选择器
来源:http://blog.csdn.net/linglongxin24/article/details/37933527


猜你喜欢
- 一、场景Android项目的开发过程中,我们项目中的gradle的dependencies闭包中会引入很多三方依赖库,引入的库越多,越容易产
- 要想实现android手机通过扫描名片,得到名片信息,可以使用脉可寻提供的第三方SDK,即Maketion ScanCard SDK,脉可寻
- 一、原理区别:Java * 是利用反射机制生成一个实现代理接口的匿名类,在调用具体方法前调用InvokeHandler来处理。而cglib
- 引言 在多线程中,为了使线程安全,我们经常会使用synchronized和Lock进行代码同步和加锁,但是具体两者有什么区别,什
- 本文实例讲述了Android编程之动态壁纸。分享给大家供大家参考,具体如下:从android 2.1版本起引入了动态壁纸的概念,熟悉andr
- 目录1,基本介绍2,HttpURLConnection实现3.HttpClient实现4.Spring的RestTemplate1,基本介绍
- using System;using System.Collections.Generic;using System.ComponentMo
- 首先,查到java里文件重命名的方法为:renameTo();我将180张图片放在d:\\backup下,用下面的程序进行重命名:publi
- 研究其父类时候发现,可以设置这么一条属性,在AlertDialog.Builder.create()之后才能调用这两个方法方法一:setCa
- 记录自己用java swing做的第一个简易界面。LoginAction.javapackage com.QQUI0819;import j
- 本文实例为大家分享了Intent实现页面跳转的两种的方法,供大家参考,具体内容如下下图中两个不同的方法就是两种页面之间跳转的情况1).跳转不
- springmvc dao层和service层的区别首先解释面上意思,service是业务层,dao是数据访问层这个问题我曾经也有过,记得以
- Csv文件基本的属性csv文件可以在excel或者wps中以表格形式打开,本质上是每一列以,逗号为分隔符的一种格式,在C#中操作可以把他当做
- 原理是使用LinkedHashMap来实现,当缓存超过大小时,将会删除最老的一个元组。实现代码如下所示import java.util.Li
- 在上篇文章,我们介绍了Get方法的设计过程和测试结果,现在我们需要对前面代码进行重构和修改,本篇需要完成以下目标。1)重构Get方法2)如何
- 在微信公众号里面需要上传头像,时间比较紧,调用学习jssdk并使用 来不及 就用了input1、使用input:file标签, 去调用系统默
- 前言进入到 SpringBoot2.7 时代,有小伙伴发现有一个常用的类忽然过期了:在 Spring Security 时代,这个类可太重要
- 壹、入围方案Sentinelgithub地址:https://sentinelguard.io/zh-cn/docs/introductio
- @CompentScan excludeFilters配置无效@CompentScan 注解配置需要扫描的包excludeFilters 是
- 一、实现对ScrollViewer样式的自定义主要包括:1、滚动条宽度设置2、滚动条颜色3、滚动条圆角4、滚动条拉动时的效果mouseove