gpt4 book ai didi

java - Android DatePicker setOnClickListener

转载 作者:太空宇宙 更新时间:2023-11-04 12:06:32 25 4
gpt4 key购买 nike

我有2个android日期选择器,我想在每个日期选择器中获取dayOfWeek,但即使我更改它,我也只能得到初始日历日。如何设置clickListener?我想在 dayOfWeek 和 dayOfWeek1 变量中获取星期几。

    dpTake=(DatePicker) rootView.findViewById(R.id.dpTake);
dpDelivery=(DatePicker) rootView.findViewById(R.id.dpDelivery);


Date dt = new Date();
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
dayOfWeek = c.get(Calendar.DAY_OF_WEEK);


dpDelivery.updateDate(c.YEAR, c.MONTH, c.DAY_OF_MONTH);

c.add(Calendar.DATE, 1);
dt = c.getTime();
dpTake.setMinDate(dt.getTime());

CalendarView cv = dpTake.getCalendarView();
long current = cv.getDate();
cv.setDate(cv.getMaxDate(), false, true);
cv.setDate(current, false, true);


c.add(Calendar.DATE, 2);
dt = c.getTime();
dpDelivery.setMinDate(dt.getTime());
CalendarView cvDelivery = dpDelivery.getCalendarView();
current = cvDelivery.getDate();
cvDelivery.setDate(cv.getMaxDate(), false, true);
cvDelivery.setDate(current, false, true);
dayOfWeek1 = c.get(Calendar.DAY_OF_WEEK);

最佳答案

试试这个代码

DatePickerDialog dpd = DatePickerDialog.newInstance(
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, monthOfYear);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);

}
},
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
);
dpd.setAccentColor(Color.parseColor("#029789"));
dpd.setMinDate(Calendar.getInstance());
dpd.show(getActivity().getFragmentManager(), "Datepickerdialog");

关于java - Android DatePicker setOnClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40300740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com