Products to do check-in function, check-in function to be based on a calendar, so on the basis of custom customized a calendar
Custom controls believe that doing Android knows:
(1) First create a class, inherit a container class, or a control
(2) Then you need to set the attributes, etc., in the Attrs folder
(3) Then it is in the class inside the property settings and layout, and so on to add functions
In fact, a custom calendar problem is not much, many people will think that through a GridView and then fill it, it is, it is mainly in the display of the first day of the month and how many days a month to show a bit around.
train of thought: by judging the current day of the week and then the calendar fill, but the size of the fill can not be greater than the number of days of the month, the first days of the month is the week to determine from which location fill.
Code:
Package Com.example.calenderdemo;
Import Android.content.Context;
Import Android.graphics.Color;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.BaseAdapter;
Import Android.widget.TextView;
public class Calendarviewadapter extends Baseadapter {private context mcontext;
private int mcountday = 49;
private int mcurrent_mouth_countday;
private int mcurrent_week; private int id[] = {r.string.week7, r.string.week1, R.string.week2, R.string.week3, R.string.week4, R.string.week5, R.st
RING.WEEK6};
Public Calendarviewadapter (context context, int countday) {this.mcontext = context;
This.mcurrent_week = Utils.getcurrentmonthstart ();
This.mcurrent_mouth_countday = Countday;
@Override public int GetCount () {return mcountday;
@Override public Object getitem (int position) {return null;
@Override public long getitemid (int position) {return position; @Override public View getview (int position, View Convertview, ViewGroup parent) {Viewholder holder = null;
if (Convertview = = null) {holder = new Viewholder ();
Convertview = Layoutinflater.from (Mcontext). Inflate (R.layout.item_calendar, NULL);
Holder.mtv_calendar_day = (TextView) convertview. Findviewbyid (R.id.tv_calendar_day);
Convertview.settag (holder);
else Holder = (viewholder) convertview.gettag ();
if (position <= 6) {Holder.mTv_calendar_day.setTextColor (color.black);
Holder.mTv_calendar_day.setTextSize (Mcontext.getresources (). Getdimension (r.dimen.text_size_7));
Holder.mTv_calendar_day.setText (Mcontext.getresources (). getString (id[position)); else {if (Mcurrent_week = 7 && (position-6) <= mcurrent_mouth_countday) {Holder.mTv_calendar_day.setTex
T (position-6 + ""); else if (position-7>= mcurrent_week && position-mcurrent_week-6 <= mcurrent_mouth_countday) {Holde
R.mtv_calendar_day.settext (position-mcurrent_week-6 + ""); } if (position% 7 = = 6) {Holder.mTv_calendar_day.setBackgroundResource (r.drawable.line_right);
}else if (position% 7 = 0) {holder.mTv_calendar_day.setBackgroundResource (r.drawable.line_left);
return convertview;
Class Viewholder {TextView mtv_calendar_day;
}
}
Populating the GridView with a simple calendar control is OK.
Demo:http://xiazai.jb51.net/201609/yuanma/androidcalenderdemo (jb51.net). rar
Custom calendar will be done after the check-in, sign in as long as the custom calendar slightly modified in the good, look at the effect of the picture:
Look, it's OK, then Demo:http://xiazai.jb51.net/201609/yuanma/androidcalender (jb51.net). rar
Added several methods of Demo:http://xiazai.jb51.net/201609/yuanma/calenderchange (jb51.net). rar
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.