怎么在adapter里调用显示日期控件呢?

彩虹蜡染的天色 2014-01-09 11:51:05
我把下面的代码写在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);

}
...全文
145 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 1 楼 s478853630 的回复:
/**
	 * 弹出日期对话框
	 * @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();
	}
谢谢你了 搞定了
s478853630 2014-01-09
  • 打赏
  • 举报
回复
/**
	 * 弹出日期对话框
	 * @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();
	}

80,361

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧