Android开源时间选择控件

移动开发
一款强大的时间选择控件

源码简介

 

一款强大的时间选择控件

 

源码运行截图

 

代码片段:

  1. @Override 
  2. public void onClick(View v) { 
  3.     // TODO Auto-generated method stub 
  4.   
  5.     final CalendarPickerView dialogView = (CalendarPickerView) getLayoutInflater() 
  6.             .inflate(R.layout.dialog, nullfalse); 
  7.     if (text.getText().toString().equals("")) { 
  8.         dialogView.init(new Date(), month.getTime()) 
  9.                 .withSelectedDate(new Date()); 
  10.     } else { 
  11.         Date date = DateUtils.getDate(text.getText().toString(), 
  12.                 "yyyy-MM-dd"); 
  13.         dialogView.init(new Date(), month.getTime()) 
  14.                 .withSelectedDate(date); 
  15.     } 
  16.   
  17.     new AlertDialog.Builder(MainActivity.this
  18.             .setTitle("时间选择控件"
  19.             .setView(dialogView) 
  20.             .setNeutralButton("返回"
  21.                     new DialogInterface.OnClickListener() { 
  22.                         @Override 
  23.                         public void onClick( 
  24.                                 DialogInterface dialogInterface, 
  25.                                 int i) { 
  26.                             dialogInterface.dismiss(); 
  27.                         } 
  28.                     }) 
  29.             .setPositiveButton("确定"
  30.                     new DialogInterface.OnClickListener() { 
  31.                         @Override 
  32.                         public void onClick( 
  33.                                 DialogInterface dialogInterface, 
  34.                                 int i) { 
  35.                             long sd = dialogView.getSelectedDate() 
  36.                                     .getTime(); 
  37.                             Date dat = new Date(sd); 
  38.                             GregorianCalendar gc = new GregorianCalendar(); 
  39.                             gc.setTime(dat); 
  40.                             java.text.SimpleDateFormat format = new java.text.SimpleDateFormat( 
  41.                                     "yyyy-MM-dd "); 
  42.                             String sb = format.format(gc.getTime()); 
  43.                             text.setText(sb); 
  44.                             dialogInterface.dismiss(); 
  45.                         } 
  46.                     }).create().show(); 

源码链接:http://down.51cto.com/data/1968738

责任编辑:chenqingxiang 来源: 网络整理
相关推荐

2017-03-20 14:46:07

Android日期时间选择器

2012-07-16 10:04:45

JavaScript

2015-01-22 15:59:07

Android源码日期时间控件SelectTime

2010-02-05 14:40:14

Android开源系统

2013-12-02 14:04:23

2015-03-03 15:53:31

Android控件

2014-11-14 10:57:24

Android控件

2013-06-08 09:05:06

2020-10-23 07:43:04

开源协议开源

2024-07-09 08:27:30

2021-08-14 06:49:44

谷歌Android UI

2014-09-05 11:23:40

开源

2014-03-28 13:14:33

2015-08-25 13:13:26

开源云架构开源工具

2016-01-08 13:28:00

开源GrafanaZabbix

2013-12-02 14:48:17

开源许可协议开放代码

2014-08-25 09:59:54

注解Android

2017-01-17 09:58:01

2009-09-09 22:53:34

ASP.NET 时间控

2014-09-24 11:42:46

AndroidButton
点赞
收藏

51CTO技术栈公众号