修改类
public class MyDatePicker {
DatePickerDialog mDatePickerDialog;
public interface onDateSet {
public void onDate(DatePicker view, int year, int monthOfYear,
int dayOfMonth);
}
onDateSet mOnDateSet;
public void setDateListener(onDateSet mOnDateSet) {
this.mOnDateSet = mOnDateSet;
}
public MyDatePicker(Context ctx) {
mDatePickerDialog = new DatePickerDialog(ctx, new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mOnDateSet.onDate(view, year, monthOfYear, dayOfMonth);
}
}, 2000, 1, 1);
}
public void show() {
mDatePickerDialog.show();
}
和..
public void ShowDatePicker() {
MyDatePicker myTimePicker = new MyDatePicker(this);
myTimePicker.show();
myTimePicker.setDateListener(new onDateSet() {
@Override
public void onDate(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Toast.makeText(MainActivity.this,
"date is " + year + ":" + monthOfYear+":"+dayOfMonth,
Toast.LENGTH_LONG).show();
}
});
}