我有一周的一天。还有2个按钮,我只需要点击
设置第二天和之前的按钮switch (dayOfWeek) {
case Calendar.MONDAY:
text1.setText("some text for MONDAY");
break;
case Calendar.TUESDAY:
text1.setText("some Text for TU");
break;
case Calendar.WEDNESDAY:
text1.setText("WEn");
break;
case Calendar.THURSDAY:
text1.setText("TH");
etc..
和按钮
btnPlus.setOnClick...{
//from case1 to case2, from case2 to case3 etc
}
btnMnius.setOnCli..{
//from case1 to case7
}
我需要一个循环 像这样http://www.java-examples.com/display-day-week-using-java-calendar
答案 0 :(得分:0)
如果我以正确的方式理解你,那一定是这样的:
创建一个这样的方法:
private void setDay(boolean dayIncrement){
Calendar cal = Calendar.getInstance(); //get an instance of Calenar
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); //get the current day
switch (dayOfWeek) {
//if it is monday....
case Calendar.MONDAY:
text1.setText("some text for MONDAY");
//if the plus button is pressed, the boolean dayIncrement is true
if(dayIncrement==true){
//then set the day of Calendar to the next day
cal.set(Calendar.DAY_OF_WEEK,Calendar.TUESDAY);
//if the minus button is pressed, the boolean dayIncrement is false
}else{
//then set the day of Calendar to the previous day
cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
}
break;
case Calendar.TUESDAY:
text1.setText("some Text for TU");
if(dayIncrement==true){
cal.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
}else{
cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
}
break;
case Calendar.WEDNESDAY:
text1.setText("WEn");
if(dayIncrement==true){
cal.set(Calendar.DAY_OF_WEEK,Calendar.THURSDAY);
}else{
cal.set(Calendar.DAY_OF_WEEK,Calendar.TUESDAY);
}
break;
case Calendar.THURSDAY:
text1.setText("TH");
if(dayIncrement==true){
cal.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
}else{
cal.set(Calendar.DAY_OF_WEEK,Calendar.FRIDAY);
}
break;
case Calendar.FRIDAY:
text1.setText("Fri");
if(dayIncrement==true){
cal.set(Calendar.DAY_OF_WEEK,Calendar.THURSDAY);
}else{
cal.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
}
break;
case Calendar.SATURDAY:
text1.setText("SAT");
if(dayIncrement==true){
cal.set(Calendar.DAY_OF_WEEK,Calendar.FRIDAY);
}else{
cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
}
break;
case Calendar.SUNDAY:
text1.setText("SAN");
if(dayIncrement==true){
cal.set(Calendar.DAY_OF_WEEK,Calendar.THURSDAY);
}else{
cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
}
break;
}
}
并在按钮内单击
调用此方法 yourPlusButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
setDay(true);
}
});
yourMinusButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
setDay(false);
}
});