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

Is lying really related to the nose? Everyone is Pinocchio!

I believe everyone has heard of the fairy tale &q...

Why are small red dwarf stars considered by scientists to be the cradle of life?

Stars are the main body of visible matter in the ...

Jiang Ziya's little secret! Did the small token help King Wu defeat King Zhou?

Communication in war is an extremely important li...

How should the routing antenna be placed to achieve faster Internet speed?

Recently, there has been a lot of controversy onl...

The future of mobile app development from the history of middleware

[[149563]] In the field of mobile development, we...

How much do you know about Android AOP?

picture Introduction to AOP AOP (Aspect-Oriented ...

An advertising experience that cost 8 million yuan

Today I will simply share with you some traffic a...

A review of the 2015 BAT campus recruitments: some increases and some decreases

It is the beginning of another school year, and i...

The marketing secret behind Lancôme’s nationwide popular promotions!

Recently, Lancôme's Spring Festival Garden Pa...

Amap product analysis report!

Navigation software has become an indispensable t...

Activity planning plan (with mind map)

Planning is a field that requires thinking talent...