This open source control can be compatible to the SDK8 version, can be customized to display the month and day, and the time range,
If we only want to display a two-month date selection range:
Final Calendar month =1);
You can then pass in some parameters when initializing.
1 FinalCalendarpickerview Dialogview =(Calendarpickerview) getlayoutinflater ()2. Inflate (R.layout.dialog,NULL,false);3 if(Text.gettext (). toString (). Equals ("")) {4Dialogview.init (NewDate (), Month.gettime ()). Withselecteddate (NewDate ());6}Else {7Date Date =dateutils.getdate (Text.gettext (). toString (),"Yyyy-mm-dd");9Dialogview.init (NewDate (), Month.gettime ()). Withselecteddate (date); One}
where Withselecteddate (date) indicates that the date that is currently displayed is specified and can be customized.
Specific demo code
1 Packagecom.example.timesample;2 3 ImportJava.util.Calendar;4 Importjava.util.Date;5 ImportJava.util.GregorianCalendar;6 7 ImportCom.squareup.timessquare.CalendarPickerView;8 ImportCom.squareup.timessquare.CalendarPickerView.SelectionMode;9 Ten ImportAndroid.os.Bundle; One Importandroid.app.Activity; A ImportAndroid.app.AlertDialog; - ImportAndroid.content.DialogInterface; - ImportAndroid.util.Log; the ImportAndroid.view.Menu; - ImportAndroid.view.View; - ImportAndroid.view.View.OnClickListener; - ImportAndroid.widget.Button; + ImportAndroid.widget.TextView; - ImportAndroid.widget.Toast; + A Public classMainactivityextendsActivity { at - PrivateButton btn; - PrivateTextView text; - - @Override - protected voidonCreate (Bundle savedinstancestate) { in Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); toBTN =(Button) Findviewbyid (r.id.button1); +Text =(TextView) Findviewbyid (r.id.textview1); - the FinalCalendar nextyear =calendar.getinstance (); *Nextyear.add (Calendar.year, 1); $ FinalCalendar month =calendar.getinstance ();Panax NotoginsengMonth.add (Calendar.month, 1); - theBtn.setonclicklistener (NewOnclicklistener () { + A @Override the Public voidOnClick (View v) { + //TODO auto-generated Method Stub - $ FinalCalendarpickerview Dialogview =(Calendarpickerview) getlayoutinflater () $. Inflate (R.layout.dialog,NULL,false); - if(Text.gettext (). toString (). Equals ("")) { -Dialogview.init (NewDate (), Month.gettime ()) the. Withselecteddate (NewDate ()); -}Else {WuyiDate Date =dateutils.getdate (Text.gettext (). toString (), the"Yyyy-mm-dd"); -Dialogview.init (NewDate (), Month.gettime ()) Wu . Withselecteddate (date); - } About $ NewAlertdialog.builder (mainactivity. This) -. Settitle ("Time selection Control") - . Setview (Dialogview) -. Setneutralbutton ("return", A NewDialoginterface.onclicklistener () { + @Override the Public voidOnClick ( - dialoginterface Dialoginterface, $ inti) { the Dialoginterface.dismiss (); the } the }) the. Setpositivebutton ("OK", - NewDialoginterface.onclicklistener () { in @Override the Public voidOnClick ( the dialoginterface Dialoginterface, About inti) { the LongSD =dialogview.getselecteddate () the . GetTime (); theDate dat =NewDate (SD); +GregorianCalendar GC =NewGregorianCalendar (); - gc.settime (DAT); theJava.text.SimpleDateFormat format =NewJava.text.SimpleDateFormat (Bayi"Yyyy-mm-dd"); theString SB =Format.format (Gc.gettime ()); the System.out.println (SB); - Text.settext (SB); - Dialoginterface.dismiss (); the } the }). Create (). Show (); the } the }); - the } the the @Override94 Public BooleanOncreateoptionsmenu (Menu menu) { the //inflate the menu; This adds items to the action bar if it is present. the getmenuinflater (). Inflate (R.menu.main, menu); the return true;98 } About -}
This simple small demo only realizes its powerful function of a small department, Timessquare Time Control also supports the choice of time period and other powerful features, need to use to see the source code.
Demo download
http://download.csdn.net/detail/lj419855402/8232371
A beautiful and practical Android Open Source date control Timessquare