怎么在adapter里调用显示日期控件呢?
我把下面的代码写在Activity里的话,在Activity里直接showDialog(1);这样就可以调用,
当前写在adapter里,我的adapter是写在另外一个java文件里 在adapter里怎么调用呢?
谢谢
日期代码:
private final class DateSetListener implements
DatePickerDialog.OnDateSetListener {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
String mm;
String dd;
monthOfYear = monthOfYear + 1;
if (monthOfYear <= 9) {
mm = "0" + monthOfYear;
} else {
mm = String.valueOf(monthOfYear);
}
if (dayOfMonth <= 9) {
dd = "0" + dayOfMonth;
} else {
dd = String.valueOf(dayOfMonth);
}
}
}
protected Dialog onCreateDialog(int id) {
return new DatePickerDialog(context, mDateSetListener, mYear, mMonth, mDay);
}
[解决办法]
/**
* 弹出日期对话框
* @param textView
* @param date 默认日期
*/
public void showDateDialog(TextView textView, String date) {
txtDatePicker = textView;
calendar = Calendar.getInstance();
if (!toolUtil.isBlank(date)) {
try {calendar.setTime(dateUtil.formatDate().parse(date));} catch (Exception e) {}
}
new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, monthOfYear);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
txtDatePicker.setText(dateUtil.formatDate().format(calendar.getTime()));
}
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
}
/**
* 弹出时间对话框
* @param textView
*/
public void showTimeDialog(TextView textView) {
txtDatePicker = textView;
new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
txtDatePicker.setText((hourOfDay < 10 ? "0" + hourOfDay : hourOfDay) + ":" + (minute < 10 ? "0" + minute : minute) + ":00");
}
}, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show();
}