Java 一周中的某一天
我每周有一天。和2个按钮,我只需要设置第二天和前一天点击Java 一周中的某一天,java,android,Java,Android,我每周有一天。和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.WED
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
}
我需要一个线圈
类似这样的事情如果我能正确理解你,那一定是这样的:
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;
}
}
创建如下方法:
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);
}
});
有谁能帮我回答这个问题吗。但是我不懂你的代码。我想简单地把所有天的一些staf和按钮+上,以查看第二天和第二天的数据。在按钮上-为你的时间上一天的人thx了很多。我以前试过这段代码,但现在不行了,我会试试这个。如果你只是把你的活动张贴在你做事情的地方,也许会有帮助。bajra@gmail.com请给我发电子邮件,我会把我的密码发送给thx