2个小工具到活动

时间:2012-01-13 08:22:15

标签: android

我有点问题。在我的活动中有2个datepicker小部件。当我调用第一个小部件时它就会很好,但是在第二个调用之后它会捕获旧的init数据。我该如何解决这个问题?我想我应该杀掉init对象。

private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        mDay = dayOfMonth;
        mMonth = monthOfYear;
        mYear = year;

        calendar.set(mYear, mMonth, mDay);

        if (START_DATE) {
            task.setDateStart(calendar.getTimeInMillis());  
            START_DATE = false;
        }
        if (END_DATE) {
            task.setDateEnd(calendar.getTimeInMillis());
            END_DATE = false;
        }


        updateData();

    }

};

.....

private void initDate() {
    if (START_DATE) {
        calendar.setTimeInMillis(task.getDateStart());      
    } else {
            calendar.setTimeInMillis(task.getDateEnd());            
    }

    mDay = calendar.get(Calendar.DAY_OF_MONTH);
    mMonth = calendar.get(Calendar.MONTH);
    mYear = calendar.get(Calendar.YEAR);
}

....听众

public void setStartDate(View v) {
    START_DATE = true; 
    initDate();
    showDialog(DATE_DIALOG_ID);
    }
public void setEndDate(View v) {
    END_DATE = true; 
    initDate();
    showDialog(DATE_DIALOG_ID); }

0 个答案:

没有答案