Android source code: Custom date and time control (SelectTime)

Android source code: Custom date and time control (SelectTime)

Functional classification: Life

Supported platforms: Android

Operating environment: Eclipse

Development language: Java

Development tool: Eclipse

Source code size: 90.47KB

Source code download address: http://down..com/data/1977586

Source code introduction

Attached is the source code of a custom date and time control (SelectTime) for the Android platform.

From Android Bus address: http://www.apkbus.com/forum.php?mod=viewthread&tid=174518&extra=

Source code running screenshot

Source code snippet

  1. package com.widget.time;
  2.   
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6.   
  7. import android.app.Activity;
  8. import android.app.AlertDialog;
  9. import android.content.DialogInterface;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.view.LayoutInflater;
  13. import android.view.View;
  14. import android.view.View.OnClickListener;
  15. import android.widget.Button;
  16. import android.widget.EditText;
  17.   
  18. public   class MainActivity extends Activity {
  19. WheelMain wheelMain;
  20. EditText txttime;
  21.   
  22. Button btnselecttime1, btnselecttime2, btnselecttime3;
  23.   
  24. int year, month, day, hour, min;
  25.   
  26. LayoutInflater inflater;
  27.   
  28. @Override  
  29. public   void onCreate(Bundle savedInstanceState) {
  30. super .onCreate(savedInstanceState);
  31. setContentView(R.layout.main);
  32. txttime = (EditText) findViewById(R.id.txttime);
  33. btnselecttime1 = (Button) findViewById(R.id.button1);
  34. btnselecttime2 = (Button) findViewById(R.id.button2);
  35. btnselecttime3 = (Button) findViewById(R.id.button3);
  36.   
  37. String yyyy = null ;
  38. SimpleDateFormat formatter = new SimpleDateFormat( "yyyy" );
  39. Date curDate = new Date(System.currentTimeMillis()); // Get the current time  
  40. yyyy = formatter.format(curDate);
  41.           
  42. Log.e( "-------------" , yyyy);
  43.   
  44. Calendar calendar = Calendar.getInstance();
  45.   
  46. year = calendar.get(Calendar.YEAR);
  47. month = calendar.get(Calendar.MONTH);
  48. day = calendar.get(Calendar.DAY_OF_MONTH);
  49. hour = calendar.get(Calendar.HOUR_OF_DAY);
  50. min = calendar.get(Calendar.MINUTE);
  51.   
  52. inflater = LayoutInflater.from(MainActivity. this );
  53.   
  54. btnselecttime1.setOnClickListener( new OnClickListener() {
  55.   
  56. @Override  
  57. public   void onClick(View arg0) {
  58.   
  59. final View timepickerview = inflater.inflate(
  60. R.layout.timepicker, null );
  61. ScreenInfo screenInfo = new ScreenInfo(MainActivity. this );
  62.   
  63. wheelMain = new WheelMain(timepickerview, 0 );
  64. wheelMain.screenheight = screenInfo.getHeight();
  65. wheelMain.initDateTimePicker(year, month, day, hour, min);
  66.   
  67. new AlertDialog.Builder(MainActivity. this )
  68. .setTitle( "Select time" )
  69. .setView(timepickerview)
  70. .setPositiveButton( "OK" ,
  71. new DialogInterface.OnClickListener() {
  72. @Override  
  73. public   void onClick(DialogInterface dialog,
  74. int which) {
  75. txttime.setText(wheelMain.getTime());
  76. }
  77. }).setNegativeButton( "Cancel" , null ).show();
  78.   
  79. }
  80. });
  81.   
  82. btnselecttime2.setOnClickListener( new OnClickListener() {
  83.   
  84. @Override  
  85. public   void onClick(View arg0) {
  86. LayoutInflater inflater = LayoutInflater
  87. .from(MainActivity. this );
  88. final View timepickerview = inflater.inflate(
  89. R.layout.timepicker, null );
  90. ScreenInfo screenInfo = new ScreenInfo(MainActivity. this );
  91.   
  92. wheelMain = new WheelMain(timepickerview, 1 );
  93. wheelMain.screenheight = screenInfo.getHeight();
  94. wheelMain.initDateTimePicker(year, month, day, hour, min);
  95.   
  96. new AlertDialog.Builder(MainActivity. this )
  97. .setTitle( "Select Date" )
  98. .setView(timepickerview)
  99. .setPositiveButton( "OK" ,
  100. new DialogInterface.OnClickListener() {
  101. @Override  
  102. public   void onClick(DialogInterface dialog,
  103. int which) {
  104. txttime.setText(wheelMain.getTime());
  105. }
  106. }).setNegativeButton( "Cancel" , null ).show();
  107.   
  108. }
  109. });
  110.   
  111. btnselecttime3.setOnClickListener( new OnClickListener() {
  112.   
  113. @Override  
  114. public   void onClick(View arg0) {
  115. LayoutInflater inflater = LayoutInflater
  116. .from(MainActivity. this );
  117. final View timepickerview = inflater.inflate(
  118. R.layout.timepicker, null );
  119. ScreenInfo screenInfo = new ScreenInfo(MainActivity. this );
  120.   
  121. wheelMain = new WheelMain(timepickerview, 2 );
  122. wheelMain.screenheight = screenInfo.getHeight();
  123. wheelMain.initDateTimePicker(year, month, day, hour, min);
  124.   
  125. new AlertDialog.Builder(MainActivity. this )
  126. .setTitle( "Select Year" )
  127. .setView(timepickerview)
  128. .setPositiveButton( "OK" ,
  129. new DialogInterface.OnClickListener() {
  130. @Override  
  131. public   void onClick(DialogInterface dialog,
  132. int which) {
  133. txttime.setText(wheelMain.getTime());
  134. }
  135. }).setNegativeButton( "Cancel" , null ).show();
  136.   
  137. }
  138. });
  139. }
  140. }

Source code download address: http://down..com/data/1977586

<<:  Android source code download: Android-like Tiantian Dongting player

>>:  15 Essential Development Tools for Android Java Programmers

Recommend

Beware of bricking your Surface Pro 3 after upgrading to new firmware

The high price of Surface Pro 3 makes people think...

Google's new strategy - Chrome and Android merge into one

[[154193]] On October 30, according to foreign me...

Traffic is so expensive, but conversion rate is so low?

Traffic is so expensive and conversion is so low!...

Can singing cause lung explosion? These people at risk should pay attention →

The death of a famous singer, who was reportedly ...

What other “hot words” will appear in the mobile phone industry in 2020?

I calculated that there is still about half a mon...

The history of Chaozhou flavor

Written by Wei Shuihua Header image | TuChong Cre...

Analysis of Zhang’s popular short video operations!

Many people have discussed why Zhang became so po...

Chen Changwen's method: Confessions of a community member

Every perceptive entrepreneur should practice soc...

Analysis of course distribution methods: the entire process of event planning!

This article will review all the details of this ...

WeChat 7.0.13.20 internal testing, new important function of scanning QR code

In the last few versions, WeChat has updated our ...