title: TimePicker's time does not get updated after setCurrentHour/Minute() correctly
body: <p>I am extending a DialogPreference to get the following Dialog:</p>
  
  <p><a href="https://i.stack.imgur.com/2XP5o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2XP5o.png" alt="The dialog wanted"></a></p>
  
  <p>I want it to be able to pick two times: a starting time and an ending time (for whatever reason). For this the TimePicker should always show the time on the ToggleButton that is checked.</p>
  
  <p>In order to let the user know which of both times he is currently changing, I use ToggleButtons and ensure by OnCheckedChangeListeners that exactly one is checked all the time. No problems so far. The same listeners are used to change the text on those ToggleButtons (by both, the setTextOn/setTextOff, methods).</p>
  
  <p>See the following code I use in the extended DialogPreference:</p>
  
  <pre><code>/*
  * Bind data to our content views
  * */
  @Override
  protected void onBindDialogView(View view) {
      super.onBindDialogView(view);
  
      // use 24h format
      mTimePicker = (TimePicker) view.findViewById(R.id.timePicker);
      mTimePicker.setIs24HourView(true);
  
      mToggleButtonFrom = (ToggleButton) view.findViewById(R.id.toggleButtonDisplayOnFrom);
      mToggleButtonUntil = (ToggleButton) view.findViewById(R.id.toggleButtonDisplayOnUntil);
  
      // save the time of the timepicker internally for both buttons, if there are no saved values
      if(fromHour == -1 &amp;&amp; fromMin == -1) {
          fromHour = mTimePicker.getCurrentHour();
          fromMin = mTimePicker.getCurrentMinute();
      }
      if(untilMin == -1 &amp;&amp; untilHour == -1){
          untilHour = mTimePicker.getCurrentHour();
          untilMin = mTimePicker.getCurrentMinute();
      }
  
      // set currently saved times
      mToggleButtonFrom.setTextOn(String.format("%02d", fromHour) + ":" + String.format("%02d", fromMin));
      mToggleButtonFrom.setTextOff(String.format("%02d", fromHour) + ":" + String.format("%02d", fromMin));
      mToggleButtonUntil.setTextOn(String.format("%02d", untilHour) + ":" + String.format("%02d", untilMin));
      mToggleButtonUntil.setTextOff(String.format("%02d", untilHour) + ":" + String.format("%02d", untilMin));
  
      // update the button (not working without this)
      mToggleButtonFrom.setChecked(mToggleButtonFrom.isChecked());
      mToggleButtonUntil.setChecked(mToggleButtonUntil.isChecked());
  
      // set togglebuttons to exclude each other
      mToggleButtonFrom.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              if (isChecked) {
                  // The toggle is enabled
                  if (mToggleButtonUntil.isChecked())
                      mToggleButtonUntil.setChecked(false);
              } else {
                  // The toggle is disabled
                  if (!mToggleButtonUntil.isChecked())
                      mToggleButtonUntil.setChecked(true);
                  fromHour = getCurrentlyPickedHour2();
                  fromMin = getCurrentlyPickedMinute2();
                  String time = getStringTime(fromHour, fromMin);
                  mToggleButtonFrom.setTextOff(time);
                  mToggleButtonFrom.setTextOn(time);
                  setTimeToTimePickerSlim(false);
              }
          }
      });
  
      mToggleButtonUntil.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              if (isChecked) {
                  // The toggle is enabled
                  if (mToggleButtonFrom.isChecked())
                      mToggleButtonFrom.setChecked(false);
              } else {
                  // The toggle is disabled
                  if (!mToggleButtonFrom.isChecked())
                      mToggleButtonFrom.setChecked(true);
                  untilHour = getCurrentlyPickedHour2();
                  untilMin = getCurrentlyPickedMinute2();
                  String time = getStringTime(untilHour, untilMin);
                  mToggleButtonUntil.setTextOff(time);
                  mToggleButtonUntil.setTextOn(time);
                  setTimeToTimePickerSlim(true);
              }
          }
      });
  
  }
  
  private void setTimeToTimePickerSlim(boolean from){
      if(from){
          mTimePicker.setCurrentHour(Integer.valueOf(fromHour));
          mTimePicker.setCurrentMinute(Integer.valueOf(fromMin));
      } else {
          mTimePicker.setCurrentHour(Integer.valueOf(untilHour));
          mTimePicker.setCurrentMinute(Integer.valueOf(untilMin));
      }
  }
  
  private int fromHour = -1;
  private int fromMin = -1;
  private int untilHour = -1;
  private int untilMin = -1;
  
  private int getCurrentlyPickedHour2(){
      return mTimePicker.getCurrentHour();
  }
  
  private int getCurrentlyPickedMinute2(){
      return mTimePicker.getCurrentMinute();
  }
  
  private String getStringTime(int hour, int min){
      return String.format("%02d", hour)+":"+String.format("%02d", min);
  }
  </code></pre>
  
  <p>I have absolutly no clue, why the TimePicker is not updating to the shown (and set) time, when I choose a new time and then click on one of those ToggleButtons (same behaviour for both of them as far as I can tell). </p>
  
  <p>But the most interesting part comes now: When I do this twice (choose a new time, toggle the buttons, choose another time, toggle again), the TimePicker starts toggling the shown time, too. Exactly what I want it to show! </p>
  
  <p>I tried a lot of things, here are my 'best' guesses:</p>
  
  <p>If I change the method setTimeToTimePickerSlim(boolean) to</p>
  
  <pre><code>    private void setTimeToTimePickerSlim(boolean from){
      if(from){
          mTimePicker.setCurrentHour(3);
          mTimePicker.setCurrentMinute(15);
      } else {
          mTimePicker.setCurrentHour(21);
          mTimePicker.setCurrentMinute(45);
      }
  }
  </code></pre>
  
  <p>this works like intended (but is of cause a bit to static to be usefull ..). Unfortunately removing the Integer.valueOf() does not help, too.</p>
  
  <p>I would be very happy for any hint (since I am trying to debug this for hours now).</p>
  
  <p><strong>Update:</strong> I logged the values by the following modification</p>
  
  <pre><code> private void setTimeToTimePickerSlim(boolean from){
      Log.i("StrangeBugTest", "Before setting: from: " + fromHour + ":" + fromMin + "   until: " + untilHour + ":" + untilMin + "   (from=" + from + ")");
      Log.i("StrangeBugTest", "Pickertime: " + mTimePicker.getCurrentHour() + ":" + mTimePicker.getCurrentMinute());
      if(from){
          mTimePicker.setCurrentHour(fromHour);
          mTimePicker.setCurrentMinute(fromMin);
      } else {
          mTimePicker.setCurrentHour(untilHour);
          mTimePicker.setCurrentMinute(untilMin);
      }
      Log.i("StrangeBugTest", "After setting: from: " + fromHour + ":" + fromMin + "   until: " + untilHour + ":" + untilMin + "   (from=" + from + ")");
      Log.i("StrangeBugTest", "Pickertime: " + mTimePicker.getCurrentHour() + ":" + mTimePicker.getCurrentMinute());
  }
  </code></pre>
  
  <p>When I start the app (and open the preferenceDialog) I get the following screen:</p>
  
  <p><a href="https://i.stack.imgur.com/ImAYX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ImAYX.jpg" alt="on start"></a></p>
  
  <p>I than picked the hour 21 (because I am using 24h-format) and minute 45. After this i clicked the toggleButtonFrom (on the left). This gets me the following log (shortened):</p>
  
  <ul>
  <li>10-20 19:43:11.575  Before setting: from: 21:45   until: 19:42   (from=false)</li>
  <li>10-20 19:43:11.575  Pickertime: 21:45</li>
  <li>10-20 19:43:11.575  After setting: from: 21:45   until: 19:42   (from=false)</li>
  <li>10-20 19:43:11.575  Pickertime: 21:45</li>
  </ul>
  
  <p>This is wrong, because the pickertime should be 19:42 after the setting. However, the gui is consistent to the picked time:</p>
  
  <p><a href="https://i.stack.imgur.com/JOWzx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JOWzx.jpg" alt="after first toggle"></a></p>
  
  <p>I than changed the Picker back to hour, chose hour 15 followed by minute 15 and clicked on ToggleButtonUntil (right one). This gives me the following log</p>
  
  <ul>
  <li>10-20 19:44:26.178  Before setting: from: 21:45   until: 15:15   (from=true)</li>
  <li>10-20 19:44:26.178  Pickertime: 15:15</li>
  <li>10-20 19:44:26.188  After setting: from: 21:45   until: 15:15   (from=true)</li>
  <li>10-20 19:44:26.188  Pickertime: 21:45</li>
  </ul>
  
  <p>This is how it should work from the very beginning! The GUI shows:</p>
  
  <p><a href="https://i.stack.imgur.com/37Pop.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/37Pop.jpg" alt="after second toggle"></a></p>
  
  <p>From here on, everything is fine, both, times and buttons toggle as intended. But I do not see, why the first one does not work. I would be happy for every hint I can get.</p>