【问题标题】:Day of week Android [closed]星期几Android [关闭]
【发布时间】:2014-11-12 12:55:57
【问题描述】:

我有星期几。还有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

【问题讨论】:

  • 谁能帮我谢谢-

标签: java android


【解决方案1】:

如果我理解你的方式是正确的,那一定是这样的:

创建一个这样的方法:

 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);
              }

      });

【讨论】:

  • 谢谢回答人。但我不明白你的代码。我想简单地在所有日子里放一些员工,然后在按钮+上查看第二天​​和第二天的数据。在按钮上 - 到前一天
  • 感谢您的宝贵时间。我之前尝试过代码,现在它不起作用我会试试这个。再次感谢
  • 如果您只是将您的活动发布在您做您的事情的地方,也许会有所帮助..
  • senad.bajra@gmail.com 请给我发电子邮件,我会发送我的代码 thx
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-31
  • 1970-01-01
  • 2011-12-27
  • 1970-01-01
  • 2021-03-18
  • 2016-10-22
  • 2015-05-13
相关资源
最近更新 更多