The most powerful calendar control in Android history

Source: Internet
Author: User
Tags dateformat

※effect




※ How to use
Package Com.fancyy.calendarweight;import Java.util.arraylist;import Java.util.list;import android.app.Activity; Import Android.content.context;import Android.graphics.drawable.bitmapdrawable;import Android.os.Bundle;import Android.view.gravity;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.viewgroup.layoutparams;import Android.view.animation.animationutils;import Android.widget.Button; Import Android.widget.linearlayout;import Android.widget.popupwindow;import Android.widget.relativelayout;import Android.widget.textview;import Com.fancyy.calendarweight.kcalendar.oncalendarclicklistener;import Com.fancyy.calendarweight.kcalendar.oncalendardatechangedlistener;public class Mainactivity extends Activity { String date = null;//Setting the default selected date format is "2014-04-05" for the standard day format button bt;protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); bt = (Button) Findviewbyid (R.ID.BT); Bt.setonclicklisteneR (New Onclicklistener () {public void OnClick (View v) {New popupwindows (Mainactivity.this, BT);}}); public class Popupwindows extends Popupwindow {public popupwindows (Context mcontext, view parent) {View view = View.inflat E (Mcontext, r.layout.popupwindow_calendar,null); View.startanimation (Animationutils.loadanimation (MContext, r.anim.fade_in)); LinearLayout ll_popup = (linearlayout) View.findviewbyid (r.id.ll_popup); Ll_popup.startanimation ( Animationutils.loadanimation (mcontext,r.anim.push_bottom_in_1)); SetWidth (layoutparams.fill_parent); SetHeight ( layoutparams.fill_parent); setbackgrounddrawable (new bitmapdrawable ()); Setfocusable (true); Setoutsidetouchable ( true); Setcontentview (view); Showatlocation (parent, Gravity.bottom, 0, 0); update (); final TextView Popupwindow_ Calendar_month = (TextView) View.findviewbyid (r.id.popupwindow_calendar_month); final Kcalendar calendar = (Kcalendar) View.findviewbyid (R.id.popupwindow_calendar); Button Popupwindow_calendar_bt_enter = (button) View.findviewbyid (r.id.Popupwindow_calendar_bt_enter);p Opupwindow_calendar_month.settext (calendar.getcalendaryear () + "year" + Calendar.getcalendarmonth () + "month"); if (null! = date) {int years = Integer.parseint (date.substring (0,date.indexof ("-")) int month = Integer.parseint (date.substring (Date.indexof ("-") + 1, date.lastindexof ("-")));p Opupwindow_calendar_ Month.settext (Years + "year" + Month + "month"), Calendar.showcalendar (years, month); Calendar.setcalendardaybgcolor (date, r.drawable.calendar_date_focused);} list<string> list = new arraylist<string> (); Set the tag list List.add ("2014-04-01"), List.add ("2014-04-02"); Calendar.addmarks (list, 0);// Listen for the selected date Calendar.setoncalendarclicklistener (new Oncalendarclicklistener () {public void Oncalendarclick (int row, int Col, String dateformat) {int month = Integer.parseint (dateformat.substring (Dateformat.indexof ("-") + 1, Dateformat.lastindexof ("-"))); if (Calendar.getcalendarmonth ()-month = = 1//cross-year Jump | | calendar.getcalendarmonth ()-month = = -11) {calendar.lastmonth ();} else if (mOnth-calendar.getcalendarmonth () = = 1//cross-year Jump | | Month-calendar.getcalendarmonth () = = -11) {calendar.nextmonth ();} else {calendar.removeallbgcolor (); Calendar.setcalendardaybgcolor (dateformat,r.drawable.calendar_date_focused);d ate = dateformat;//last returned to global Date}}}) ;//monitor Current month Calendar.setoncalendardatechangedlistener (new Oncalendardatechangedlistener () {public void oncalendardatechanged (int, int month) {Popupwindow_calendar_month.settext (year + "years" + month + "month");}); /Last month monitor button relativelayout Popupwindow_calendar_last_month = (relativelayout) View.findviewbyid (R.id.popupwindow_ Calendar_last_month);p Opupwindow_calendar_last_month.setonclicklistener (new Onclicklistener () {public void OnClick (View v) {Calendar.lastmonth ();}}); /Next month monitor button relativelayout Popupwindow_calendar_next_month = (relativelayout) View.findviewbyid (R.id.popupwindow_ Calendar_next_month);p Opupwindow_calendar_next_month.setonclicklistener (new Onclicklistener () {public void OnClick (View v) {Calendar.nextmonth ();}}); /Close Window PopupWindow_calendar_bt_enter.setonclicklistener (New Onclicklistener () {public void OnClick (View v) {dismiss ();}});}} 
※demo Downloadhttp://download.csdn.net/detail/u010785585/8016687



The most powerful calendar control in Android history

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.