How to use the Android custom calendar

Source: Internet
Author: User

Midnight Dead Light 123 provides a custom Android calendar with his blog address as follows:

http://blog.csdn.net/huangyanbin123/article/details/38350213

He provided the code in addition to the custom calendar, there is a demo, for most people, just need to show a calendar, and respond to the calendar click event. So I simplified his demo, gave a more simple demo and use method, the method is divided into three steps:

First step: Import

http://download.csdn.net/detail/huangyanbin123/7723323

Code in the. Because this is not a library project, simply add the source code to your project.

The second step: to create a layout file as follows, mainly android.support.v4.view.ViewPager to be placed in the appropriate location, it is the container of the Calendar control.

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "xmlns:textcircle=" Http://schemas.android.com/apk/res/com.example.calendar "Android: Layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > <LinearLa Yout android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:background= "#fff        Ffe "android:orientation=" vertical "android:paddingleft=" 10dip "android:paddingright=" 10dip "> <view android:layout_width= "fill_parent" android:layout_height= "1px" android:layou            T_alignparenttop= "true" android:background= "#20000000" > </View> <tablelayout Android:layout_width= "Fill_parent" android:layout_height= "20dip" android:layout_marginbottom= "2d  IP "android:layout_margintop=" 2dip ">          <TableRow> <textview style= "@style/datestyle" Android Oid:text= "Day" android:textcolor= "@color/date_1"/> <textview sty                le= "@style/datestyle" android:text= "one" android:textcolor= "@color/date_2"/>                    <textview style= "@style/datestyle" android:text= "two"                    Android:textcolor= "@color/date_2"/> <textview style= "@style/datestyle"                    android:text= "three" android:textcolor= "@color/date_2"/> <textview style= "@style/datestyle" android:text= "four" android:textcolor= "@color/date_2                    "/> <textview style=" @style/datestyle "android:text=" five " Android:texTcolor= "@color/date_2"/> <textview style= "@style/datestyle" an Droid:text= "Six" android:textcolor= "@color/date_1"/> </TableRow> </tablela yout> <view android:layout_width= "fill_parent" android:layout_height= "1px" a Ndroid:layout_alignparenttop= "true" android:background= "#20000000" > </View> </linearlayo ut> <relativelayout android:id= "@+id/contentpager2" android:layout_width= "Fill_parent" Andro id:layout_height= "Fill_parent" android:layout_weight= "1" android:background= "#fffffe" > <androi            D.support.v4.view.viewpager android:id= "@+id/viewpager2" android:layout_width= "Fill_parent"             android:layout_height= "wrap_content" android:layout_gravity= "center" android:background= "#F7F7F7" Android:paddingleft= "15dip" android:paddingright= "10dip" > </android.support.v4.view.ViewPager> </rel Ativelayout></linearlayout>

Step three: Create your own activity class, as follows:

Package Com.kidapk.www;import Android.app.activity;import Android.os.bundle;import Android.support.v4.view.viewpager;import Android.widget.toast;import Com.example.calendar.r;import Com.example.calendar.doim.calendarviewbuilder;import Com.example.calendar.doim.customdate;import Com.example.calendar.widget.calendarview;import Com.example.calendar.widget.calendarview.callback;import Com.example.calendar.widget.calendarviewpagerlisenter;import Com.example.calendar.widget.CustomViewPagerAdapter ;p ublic class Testcalendaractivity extends Activity implements Callback{private Viewpager viewpager;private calendarview[] views;private calendarviewbuilder builder = new Calendarviewbuilder (); @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_test);// Initialize control Viewpager = (Viewpager) This.findviewbyid (r.id.viewpager2); views = Builder.createmasscalendarviews (This, 5, this   ); Produce multiple Calendarviewthis.findviewbyid (R.id.contentpager2);//Set control customviewpageradapter<calendarview> viewpageradapter = new Customviewpageradapter<calendarview   > (views); Viewpager.setadapter (Viewpageradapter); Viewpager.setcurrentitem (498); Views can be flipped 498 pages Viewpager.setonpagechangelistener (new Calendarviewpagerlisenter (Viewpageradapter));} @Overridepublic void Clickdate (customdate date) {Toast.maketext (this, date.year+ "-" +date.month+ "-" +date.day, Toast.length_short). Show ();} @Overridepublic void onmesurecellheight (int cellspace) {} @Overridepublic void ChangeDate (customdate date) {}}
The effect of the app is as follows:




How to use the Android custom calendar

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.