2012-12-28 65 views
1

你好,請找到下面的代碼,我現在面臨的問題與時間對話監聽方法,它調用的兩次listener.How固定聽衆一次。TimePickerListener調用兩種方法同時

@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

你好這個問題只與Android模擬器版本4.1,運行它的另一個版本好。