我有显示日期的按钮。在这个,如果我选择周末的日期,那么我希望它应该立即提示消息。 我运行的代码只检查myDay == 2。如果我选择星期六,不是myDay == 1。当我选择周末时,我应该显示当前日期而不是选择的周末日期。
private void setupDate(int day, int month, int year) {
Calendar cal = Calendar.getInstance();
cal.set(day, month, year);
int myDay = cal.get(Calendar.DAY_OF_WEEK);
if (myDay == 1 || myDay == 2) {
Toast.makeText(DateTimePickerActivity.this, "My good day is " + myDay, Toast.LENGTH_SHORT).show();
} else {
String strMonth = ((month + 1) <= 9) ? ("0" + (month + 1)) : String.valueOf(month + 1);
views.button_date.setText(String.valueOf(day) + "/" + strMonth + "/" + String.valueOf(year));
}
}
private void showDatePickerDialog() {
DatePickerDialog datepickerdialog = new DatePickerDialog
(
this,
dpListenerView,
/* new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
} },*/
//this,
x_year,
month,
day
);
datepickerdialog.show();
}
class ButtonViews {
Button button_time;
Button button_date;
public ButtonViews() {
button_date = (Button) findViewById(R.id.button_date);
button_time = (Button) findViewById(R.id.button_time);
}
}
class dpListener implements OnDateSetListener {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
setupDate(dayOfMonth, monthOfYear, year);
}
}
答案 0 :(得分:0)
我认为你对Calendar.DAY_OF_WEEK
星期六= 7
使用,
if(myDay == 1 || myDay == 7){}