title: Waiting for TimePickerFragment to return time
body: <p>New to JAVA and Android coding and trying my first practical project.</p>
  
  <p>I don't understand how to make processing wait until timekeeperdialog returns a value.</p>
  
  <p>In my Main Activity I have created getters and setters to variables (first time doing this btw):</p>
  
  <pre><code>    private int pickhour;
      private int pickminute;
  
      public MainActivity(){
  
          pickhour = 0;
          pickminute = 0;
  
  
      }
  
  
  
      public void setpickhour(int pickhour) {
          this.pickhour = pickhour;
  
      }
  
      public int getpickhour(){
          return this.pickhour;
      }
  
      public void setpickminute(int pickminute) {
          this.pickminute = pickminute;
  
      }
  
      public int getPickminute(int pickminute) {
          return this.pickminute;
  
      }
  </code></pre>
  
  <p>I call the dialog box with this, and then expecting processing to pause until the TimePicker returns a value, I have a Toast to show results. The Toast fires as soon as the Timepicker appears.</p>
  
  <pre><code>DialogFragment newFragment = new TimePickerFragment();
          newFragment.show(getFragmentManager(),"TimePicker");
  
    Toast.makeText(getApplicationContext(), "Time Picker" + String.valueOf(pickhour) + ":" + String.valueOf(pickminute), Toast.LENGTH_LONG).show();
  </code></pre>
  
  <p>And my fragment looks like this :</p>
  
  <pre><code>public class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener{
  
  private MainActivity ma = new MainActivity();
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState){
      //Use the current time as the default values for the time picker
      final Calendar c = Calendar.getInstance();
      int hour = c.get(Calendar.HOUR_OF_DAY);
      int minute = c.get(Calendar.MINUTE);
  
      //Create and return a new instance of TimePickerDialog
      return new TimePickerDialog(getActivity(),this, hour, minute,
              DateFormat.is24HourFormat(getActivity()));
  }
  
  //onTimeSet() callback method
  public void onTimeSet(TimePicker view, int hourOfDay, int minute){
      //Do something with the user chosen time
      //Get reference of host activity (XML Layout File) TextView widget
  
      ma.setpickhour(hourOfDay);
      ma.setpickminute(minute);
  
  
  
  
  
  }
  
  }
  </code></pre>
  
  <p>I tried looping through a boolean set by the  ontimeset method to force waiting on a return value, but my application just hung.</p>
  
  <p>What fundamental concept am I missing? I'm on vacation, so spent a day &amp; a half trying to figure this out.</p>