gpt4 book ai didi

android - 如何在 Android 的 DatePicker fragment 中禁用 future 日期选择?

转载 作者:行者123 更新时间:2023-11-29 14:31:12 25 4
gpt4 key购买 nike

所以我已经阅读了其他帖子,但仍然无法正常工作。我想禁用某人从我的日期选择器 fragment 中选择 future 日期的能力。任何帮助将不胜感激,谢谢!

[更新] 2015 年 4 月 26 日 - 已解决,每个发表评论或回答的人 - 他们的解决方案都有效。

调用日期选择器的函数:

mSearchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatePickerFragment datePickerFragment = new DatePickerFragment();
datePickerFragment.show(getSupportFragmentManager(), "datepicker");

}
});

DatePickerFragment代码:

public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {

public EditText editText;
DatePicker dpResult;

public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);

return new DatePickerDialog(getActivity(), this, year, month, day);

}

public void onDateSet(DatePicker view, int year, int month, int day) {

Intent goSearchSelectedDate = new Intent(getActivity(), SearchByDate.class);
goSearchSelectedDate.putExtra("day", String.valueOf(day));
goSearchSelectedDate.putExtra("month", String.valueOf(month));
goSearchSelectedDate.putExtra("year", String.valueOf(year));
Log.d("month", String.valueOf(year));
startActivity(goSearchSelectedDate);

}
}

最佳答案

您只需在 DatePickerDialog 中添加一行

datePicker.getDatePicker().setMaxDate(calendar.getTimeInMillis());

关于android - 如何在 Android 的 DatePicker fragment 中禁用 future 日期选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29771912/

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