Andorid Calendar Control Library, can slide left and right, display Gregorian calendar, lunar calendar, holidays and other functions _android

Source: Internet
Author: User
Tags stringbuffer

Cover Chart:

Demo Effect Chart

SOURCE directory Structure

Features

    1. Slide the calendar around.
    2. Displays Gregorian calendar, lunar calendar, holidays and Shiber
    3. Implement a single or multiple selection of a month's date.

Use steps

Gradle Dependency

ADD the library to your project Build.gradle

Compile ' com.joybar.calendar:librarycalendar:1.0.4 '

Sample Usage

Implement Onpagechangelistener and Ondateclicklistener interface, if you implement multiple selections, you need to implement Ondatecancellistener

 public class Mainactivity extends Appcompatactivity implements Calendarviewpagerfragment.onpagechangelistener, Calen

 Darviewfragment.ondateclicklistener, Calendarviewfragment.ondatecancellistener {private TextView tv_date;

 Private Boolean ischoicemodelsingle = false;

 

 Private list<calendardate> mlistdate = new arraylist<> ();

 @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);

 Setcontentview (R.layout.activity_main);

 Tv_date = (TextView) Findviewbyid (r.id.tv_date);

 Initfragment ();

 private void Initfragment () {Fragmentmanager fm = Getsupportfragmentmanager ();

 Fragmenttransaction tx = Fm.begintransaction ();

 Fragment Fragment = new Calendarviewpagerfragment ();

 Fragment Fragment = calendarviewpagerfragment.newinstance (Ischoicemodelsingle);

 Tx.replace (r.id.fl_content, fragment);

 Tx.commit (); @Override public boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.menu_im, menu);

 return true; @Override public boolean onoptionsitemselected (MenuItem item) {switch (Item.getitemid ()) {case r.id.menu_sing

  Le:ischoicemodelsingle = true;

  Initfragment ();

  Break

  Case r.id.menu_multi:ischoicemodelsingle = false;

  Initfragment ();

  Break

 Default:break;

 return true;

 @Override public void Ondateclick (Calendardate calendardate) {int year = Calendardate.getsolar (). Solaryear;

 int month = Calendardate.getsolar (). Solarmonth;

 int day = Calendardate.getsolar (). Solarday;

 if (ischoicemodelsingle) {Tv_date.settext (year + "-" + month + "-" + day);

  else {//system.out.println (Calendardate.getsolar (). Solarday);

  Mlistdate.add (calendardate);

 Tv_date.settext (listtostring (mlistdate));

 @Override public void Ondatecancel (Calendardate calendardate) {int count = Mlistdate.size (); for (int i = 0; i < count; i++) {Calendardate date = Mlistdate.get (i);

  if (Date.getsolar (). Solarday = = Calendardate.getsolar (). Solarday) {mlistdate.remove (i);

  Break

 } tv_date.settext (Listtostring (mlistdate));

 @Override public void Onpagechange (int year, int month) {Tv_date.settext (year + "-" + month);

 Mlistdate.clear (); private static String listtostring (list<calendardate> List) {StringBuffer stringbuffer = new StringBuffer (

 );  for (Calendardate date:list) {stringbuffer.append (Date.getsolar (). Solaryear + "-" + date.getsolar (). SolarMonth + "-"

 + Date.getsolar (). Solarday). Append ("");

 return stringbuffer.tostring ();

 }

 

}

Single or multiple-selected implementation code

 if (ischoicemodelsingle) {mgridview.setchoicemode (gridview.choice_mode_single);

 else {mgridview.setchoicemode (gridview.choice_mode_multiple); Mgridview.setonitemclicklistener (New Adapterview.onitemclicklistener () {@Override public void Onitemclick (Adapt Erview<?> Parent, view view, int position, long id) {Calendardate calendardate = ((calendargridviewadapter) Mgri

  Dview.getadapter ()). Getlistdata (). get (position); if (ischoicemodelsingle) {//Radio if (finalmlistdatacalendar.get (position). Isinthismonth ()) {Ondateclicklistene

   R.ondateclick (calendardate);

   else {mgridview.setitemchecked (position, false); } else {//multiple-Select if (Finalmlistdatacalendar.get (position). Isinthismonth ()) {//Mgridview.getcheckeditemids (

   ) if (!mgridview.isitemchecked (position)) {ondatecancellistener.ondatecancel (calendardate);

   else {Ondateclicklistener.ondateclick (calendardate); } else {MGRIDVIEW.SETITEMCHecked (position, false);

 }

 

  }

  }

 });

Git address: Https://github.com/myjoybar/android-calendar-view

The above is the Android Calendar control data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!

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.