ボタンを押して DatePickerDialog を表示すると、ダイアログに 1 か月大きく表示されます。たとえば、次のような現在の日付で開始する場合(joda ライブラリの DateTime を使用):
DateTimeZone zone = DateTimeZone.forID("Europe/Athens");
DateTime dt = new DateTime(zone);
int year = dt.getYear();
int month = dt.getMonthOfYear();
int day = dt.getDayOfMonth();
これは 07/08/2014 であり、日付ダイアログには 1 か月大きい 07/09/2014 が表示されます。なぜこれが起こるのかわかりません。
datePickerFragment を表すフラグメントは次のとおりです。
@SuppressLint("ValidFragment")
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{
@SuppressLint("ValidFragment")
TextView txtDate;
GlobalData appState;
public DatePickerFragment(TextView txtDate) {
super();
this.txtDate = txtDate;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
DateTimeZone zone = DateTimeZone.forID("Europe/Athens");
DateTime dt = new DateTime(zone);
int year = dt.getYear();
int month = dt.getMonthOfYear();
int day = dt.getDayOfMonth();
Log.i("DatePickerFragment day month year", day +" "+ month + " "+ year + "");
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
appState.setDateUserFrom(year, month, day);
Log.i("Date day month yerar", "Date changed." + day+" " + month + " " +year);
txtDate.setText(new StringBuilder().append(day)
.append("-").append(month).append("-").append(year)
.append(" "));
}
}