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
0
投稿
猜你喜欢
- 如下所示:class Program {
- 一、登录认证基于过滤器链Spring Security的登录验证流程核心就是过滤器链。当一个请求到达时按照过滤器链的顺序依次进行处理,通过所
- 出现乱码请修改为BufferedReader br = new BufferedReader(new InputStreamReader(n
- 文章来源:aspcn 作者:孙雯重复和并发服务器这个应用程序被当作一个重复的服务器.因为它只有在处理完一个进程以后才会接受另一个连接.更多的
- 介绍:unity界面开发,会用到很多导航的按钮,他们是公共的,单击其中一个按钮,显示对应的界面。unity中,UGUI自带Toggle组件,
- 将SpringBoot项目部署到腾讯云注意:1、如果已经下载好MySql和JDK,可以直接跳过1、3步骤。但是不要忘记步骤2哦。2、如果已经
- Map 中ConcurrentHashMap是线程安全的,但不是所有操作都是,例如get()之后再put()就不是了,这时使用merge()
- 目录一、准备工作1、导包二、了解注解1、常用注解2、@ExcelProperty注解3、@ColumnWith注解4、@ContentFon
- 一 Flow使用注意事项多个Flow不能放到一个lifecycleScope.launch里去collect{},因为进入collect{}
- 线程(英语:thread)是操作系统能够进行运算调度的最小单位。它被包含在进程之中,是进程中的实际运作单位。一条线程指的是进程中一个单一顺序
- 引言: 在Spring Boot应用中,基于数据某个字段进行排序是一个非常常用的需求,这里将给出Sort的三种常用用法,基于分页的应用,大家
- 1.多节点无缝切换问题分布式节点中的服务宕机或者重启不影响客户端使用分布式节点中的服务宕机重启不影响业务服务内部通信如果在某个分布式系统中想
- • 创建目录和文件1、通过Path类的Combine方法可以合并路径。string activeDir = @"C:\myDir&
- 一、实验:继承1、概念Maven工程之间,A 工程继承 B 工程B 工程:父工程A 工程:子工程本质上是 A 工程的 pom.xml 中的配
- 实践过程效果代码public partial class Form1 : Form{ public Form1()
- 本文实例为大家分享了C#导出Excel的具体代码,供大家参考,具体内容如下using System;using System.Collect
- 一、Springboot项目运行正常打包前,Springbooot项目在本地必须是运行正常的。我们这里使用本专栏写起来的项目,如下所示:来访
- Struts2是Struts社区和WebWork社区的共同成果,我们甚至可以说,Struts2是WebWork的升级版,他采用的正是WebW
- 本文实例为大家分享了java实现登录验证码功能的具体代码,供大家参考,具体内容如下登录验证码登录验证是大多数登录系统都会用到的一个功能,它的
- 对于步入编程行业不深的初学者或是已经有所领会的人来说,当学习一项新的技术的时候,非常渴望有一个附上注释完整的Demo。本人深有体会,网上的例