睡眠助手功能实现(2)

这里是时间的设置:

public void setTime() {           final Time t = new Time();           t.setToNow();           new TimePickerDialog(HelperMain.thisnew TimePickerDialog.OnTimeSetListener() {                              @Override               public void onTimeSet(TimePicker view, int hourOfDay, int minute) {                   String time ;                   if(hourOfDay > 12) {                       if((hourOfDay - 12) >= 10) {                           time = (hourOfDay - 12) + " : " + minute + "  pm" ;                       } else {                           time = "0" + (hourOfDay - 12) + " : " + minute + "  pm" ;                       }                   } else if(hourOfDay == 12) {                       time = hourOfDay + " : " + minute + "  pm" ;                   }else {                       if(hourOfDay >= 10){                           time = hourOfDay + " : " + minute + "  am" ;                       } else {                           time = "0" + hourOfDay + " : " + minute + "  am" ;                       }                   }                   //calendar.setTimeInMillis(System.currentTimeMillis());                    calendar.set(t.year,t.month,t.monthDay,hourOfDay,minute,0);                   timeShow.setText(time);                   SharedPreferences uiState = getPreferences(0);                   SharedPreferences.Editor editor = uiState.edit();                   editor.putString("time", time);                   //一定要记得在存入数据之后要调用commit方法,不然getXXX的时候会获取不到值                    editor.commit();                   if(helper) {                       openHelper();                       onOffShow.setText("开");                   }               }           }, t.hour, t.minute, false).show();                  }  

到这里就完成了开关,时间和回复内容的设置。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwjgpd.html