2017-06-13 140 views
1

我可以更改當天的突出顯示(用紅色圈出)。這是當天顯示系統,但我的應用程序工作在不同的時區,所以我如何取消突出顯示當天或將其更改爲另一天。更改日期選擇器對話框當前日期 - android java

enter image description here

private void setDateTimeField() { 
    billDate.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      billDateDialog.show(); 
      billDateDialog.updateDate(billDateCal.get(Calendar.YEAR), billDateCal.get(Calendar.MONTH), billDateCal.get(Calendar.DAY_OF_MONTH)); 
     } 
    }); 


    billDateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { 

     public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 

      // Bills need to be set to 00.00 hours. DST needs to be ignored because changing to other timezones with no DST will cause problems with days changing to the day before. 
      long correctedTime = new DayLightSavings(year, monthOfYear, dayOfMonth, timeZone).getCorrectedTime(); 
      billDateCal.setTimeInMillis(correctedTime); 
      billDate.setText(dateFormatter.format(billDateCal.getTimeInMillis())); 
     } 

    },billDateCal.get(Calendar.YEAR), billDateCal.get(Calendar.MONTH), billDateCal.get(Calendar.DAY_OF_MONTH)); 

    // Do not allow selection of <= today's date. 
    // TODO Dialogue needs to be based on timezone selection. 
    long oneDay = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS); 

    long oldRawOffset = TimeZone.getDefault().getRawOffset(); 
    long newRawOffset = timeZone.getRawOffset(); 
    long rawOffset = oldRawOffset - newRawOffset; 
    // TODO fix dialogue to display the correct timezone current day. 
    billDateDialog.getDatePicker().setMinDate(Calendar.getInstance().getTimeInMillis() + oneDay - rawOffset); 
} 
+0

什麼是當前良好的應用程序時間? – jeorfevre

+0

這可能有幫助 https://stackoverflow.com/questions/26310750/how-to-set-a-specific-date-in-date-picker-in-android –

+0

好的應用程序時間是第14日 – Mazz

回答

0

你需要做的是顯示您的對話框初始化與應用程序很好的日期對話框之前。此代碼來自android應用程序。

DatePicker datePicker = (DatePicker) billDateDialog.getDatePicker(); 
TimePicker timePicker = (TimePicker) findViewById(R.id.timepicker); 

DateTime apptime = DateTime.now() ; //From your app, db or other 
int y = apptime.getYear() ; 
int m = apptime.getMonthOfYear() - 1;  // Need to subtract 1 here. 
int d  = apptime.getDayOfMonth(); 
int h = apptime.getHourOfDay(); 
int min = apptime.getMinuteOfHour(); 

//setters 
datePicker.updateDate(y, m, d);    
timePicker.setCurrentHour(h);      
timePicker.setCurrentMinute(min); 
+0

這隻更新選定的日期,而不是突出顯示的日期以紅色 – Mazz

相關問題