1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| package com.monappli.utils;
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
public class DatePicker extends EditText {
private int year, month, day;
final int DATE_DIALOG_ID = 1;
private Context context;
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(android.widget.DatePicker view, int cYear, int cMonthOfYear, int cDayOfMonth) {
year = cYear;
month = cMonthOfYear;
day = cDayOfMonth;
}
};
private View.OnClickListener mOnClickListener =
new View.OnClickListener(){
public void onClick(View v) {
((Activity) context).showDialog(DATE_DIALOG_ID);
}
};
//Constructeurs
public DatePicker(Context cContext) {
super(cContext);
initialize(context);
}
public DatePicker(Context context, AttributeSet attrs) {
super(context, attrs);
initialize(context);
}
public DatePicker(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initialize(context);
}
public void initialize(Context context){
Calendar cal = Calendar.getInstance();
this.year = cal.get(Calendar.YEAR);
this.month= cal.get(Calendar.MONTH) + 1;
this.day = cal.get(Calendar.DAY_OF_MONTH);
this.context = context;
this.setFocusableInTouchMode(false);
this.setOnClickListener(mOnClickListener);
}
public DatePickerDialog.OnDateSetListener getDateSetListener(){
return mDateSetListener;
}
public int getMonth(){ return this.month; }
public int getYear(){ return this.year; }
public int getDay(){ return this.day; }
protected DatePickerDialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(context, mDateSetListener, this.year, this.month, this.day);
}
return null;
}
} |
Partager