在android中我试图在一个页面上使用3个datepickers。但是听众只是拿起了我最后改变的datepicker的值,它为所有3个人分配了相同的值。
我应该在date1,date5和date7中获得3个不同的值。所以我可以把它保存在数据库中。
//set the current date as default date
date = (DatePicker) findViewById(R.id.datePicker1);
date4 = (DatePicker) findViewById(R.id.datePicker2);
date6 = (DatePicker) findViewById(R.id.datePicker3);
OnDateChangedListener one_dateListener,two_dateListener,three_dateListener;
date.init(date.getYear(), date.getMonth(), date.getDayOfMonth(),
one_dateListener= new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year1,
int monthOfYear, int dayOfMonth) {
day = dayOfMonth;
month = monthOfYear;
year = Integer.toString(year1);
}
});
date1 = pad(day)+"-"+padMonth(month)+"-"+year1;
System.out.println("Date 1"+date1);
date4 = (DatePicker) findViewById(R.id.datePicker2);
date4.init(date4.getYear(), date4.getMonth(), date4.getDayOfMonth(),
two_dateListener=new OnDateChangedListener() {
public void onDateChanged(DatePicker view, int year1,
int monthOfYear, int dayOfMonth) {
day = dayOfMonth;
month = monthOfYear;
year = Integer.toString(year1);
}
});
date5 = pad(date4.getDayOfMonth())+"-"+padMonth(date4.getMonth())+"-"+date4.getYear();
date6 = (DatePicker) findViewById(R.id.datePicker3);
date6.init(date6.getYear(), date6.getMonth(), date6.getDayOfMonth(),
three_dateListener= new OnDateChangedListener()
{
public void onDateChanged(DatePicker view, int year1,
int monthOfYear, int dayOfMonth) {
day = dayOfMonth;
month = monthOfYear;
year = Integer.toString(year1);
}
}
);
date7 = pad(date6.getDayOfMonth())+"-"+padMonth(date6.getMonth())+"-"+date6.getYear();
答案 0 :(得分:0)
你应该使用DatePickerDialog& TimePickerDialog,你不会有任何问题。
在我的应用程序中,我正在使用2个不同的DatePickerDialog,它运行正常。
我刚编辑了一小部分代码。无法编辑400行代码。
private DatePickerDialog showDatePicker(){
DatePickerDialog datePicker = new DatePickerDialog(smileIt.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
mCalendar.set(Calendar.YEAR, year);
mCalendar.set(Calendar.MONTH, monthOfYear);
mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
mToday.set(Calendar.YEAR, year);
mToday.set(Calendar.MONTH, monthOfYear);
mToday.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateDateButtonText();
}
}, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
return datePicker;
}