TimePicker Listener同时调用两个方法

时间:2012-12-28 14:33:15

标签: android

嗨,请找到以下代码我遇到的Time对话监听器方法问题,它调用了两次监听器。如何修复监听器一次。

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case TIME_DIALOG_ID:
        // set time picker as current time
        return new TimePickerDialog(this, timePickerListener, hour, minute,
                false);

    }
    return null;
}

private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
    public void onTimeSet(TimePicker view, int selectedHour,
            int selectedMinute) {

        System.out.println("=========Dialog==================");

        hour = selectedHour;
        minute = selectedMinute;

        // set current time into textview
        tvDisplayTime.setText(new StringBuilder().append(pad(hour))
                .append(":").append(pad(minute)));

        // set current time into timepicker
        timePicker1.setCurrentHour(hour);
        timePicker1.setCurrentMinute(minute);

    }
};

private static String pad(int c) {
    if (c >= 10)
        return String.valueOf(c);
    else
        return "0" + String.valueOf(c);
}

请帮我拨打一次电话听众,我正在推荐这个网址: http://www.mkyong.com/android/android-date-picker-example/

我正在使用模拟器版本4.1。

1 个答案:

答案 0 :(得分:1)

嗨这个问题只有android模拟器版本4.1,它在另一个版本上运行良好。