我希望在更改日期时隐藏“确定”按钮。下面是我编写的代码,但按钮没有改变:
datePickerDialog.getDatePicker().init(year, month, day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Toast.makeText(getActivity(),
"onDateChanged " + "Year: " + year + "\n" +
"Month of Year: " + monthOfYear + "\n" +
"Day of Month: " + dayOfMonth, Toast.LENGTH_SHORT).show();
datePickerDialog.setButton(DatePickerDialog.BUTTON_POSITIVE, null, datePickerDialog);
datePickerDialog.setButton(DatePickerDialog.BUTTON_NEGATIVE, "CANCEL", datePickerDialog);
}});
非常感谢任何帮助。
答案 0 :(得分:2)
这适合我。!
int
答案 1 :(得分:0)
通过隐藏“确定”按钮,您不希望用户选择日期。 DatePicker不是您的自定义对话框,这就是为什么可能难以隐藏按钮。您可以限制用户单击“确定”按钮
datePickerDialog.getDatePicker().init(year, month, day, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Toast.makeText(getActivity(),
"onDateChanged " + "Year: " + year + "\n" +
"Month of Year: " + monthOfYear + "\n" +
"Day of Month: " + dayOfMonth, Toast.LENGTH_SHORT).show();
datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE,
"OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
if ("Your date condition") {
// perform your action
}
}
});
datePickerDialog.setButton(DatePickerDialog.BUTTON_NEGATIVE, "CANCEL", datePickerDialog);
}});