嗨我想在第一次用户打开对话框时设置日期选择器对话框上的特定日期(从服务器)。之后,日期将被动态设置。但我无法在日期选择器上获得该日期。它总是显示当前的最短日期。有没有简单的方法来解决这个问题?从datePicker对话框的服务器获取特定日期android
//My date from server
Calendar cal = Calendar.getInstance();
long l = Long.parseLong(posttime);
cal.setTimeInMillis(l);
int dmonth = cal.get(Calendar.DAY_OF_MONTH);
int dday = cal.get(Calendar.MONTH);
int dyear= cal.get(Calendar.YEAR);
dateTextView.setText(dday+" " + dmonth + " " +dyear);
//Date to be set dynamically
Calendar now = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
PostInfoUpdate.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)+1
);
dpd.setMinDate(Calendar.getInstance());
now.add(Calendar.DAY_OF_MONTH, 30);
dpd.setMaxDate(now);
//To open the dialog
public void show() {
dpd.show(getFragmentManager(), "Datepickerdialog");
}
//To set the date
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
String date = "You picked the following date: "+dayOfMonth+"/"+(++monthOfYear)+"/"+year;
dateTextView.setText(date);
}
能否请您解释清楚? – spykeburn
http://stackoverflow.com/questions/26310750/how-to-set-a-specific-date-in-date-picker-in-android你可以使用答案1中的方法将datepicker onstart设置为你想要的日期。我“引用”的代码将日期设置为当前日期(现在)。我希望这有帮助。 – Rastaman
我试过这个dpd.initialize(mCallBack,dyear,dmonth,dday);我得到了我的约会,但现在我无法更改日期。 – spykeburn