##在这里,我将日期设置为日期选择器。活动打开后,我选择日期26-11-2019,然后我打开日期选择器,它显示当前日期。你能告诉我它如何正常工作##
public void startCalenderr(View view) {
// this is my on click method here i open my date picker
curYear = calendar1.get(Calendar.YEAR);
curMonth = calendar1.get(Calendar.MONTH);
curDay = calendar1.get(Calendar.DAY_OF_MONTH);
//this is the dialog for the date picker
dialog = new DatePickerDialog(Main2Activity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
// here i set my date into text view
month += 1;
String converdate = year+"-"+month+"-"+dayOfMonth;
}, curYear, curMonth, curDay);
dialog.show();
// here i show my datepicker dialog
}
答案 0 :(得分:1)
希望这项工作为您
public void startCalenderr(View view) {
if(calendar1 == null){
calendar1 = Calendar.getInstance();
}
if(curYear <1)curYear = calendar1.get(Calendar.YEAR);
if(curMonth < 1)curMonth = calendar1.get(Calendar.MONTH);
if(curDay < 1)curDay = calendar1.get(Calendar.DAY_OF_MONTH);
//this is the dialog for the date picker
dialog = new DatePickerDialog(Main2Activity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
// here i set my date into text view
month += 1;
String converdate = year+"-"+month+"-"+dayOfMonth;
curYear = year;
curMont = month;
curDay = dayOfMonth;
}, curYear, curMonth, curDay);
dialog.show();
// here i show my datepicker dialog
}
答案 1 :(得分:0)
设置这些参数
curYear, curMonth, curDay
在构造函数的末尾直到您喜欢的日期。