title: Use DialogFragment to Validate User Entry
body: <p>I have a FragmentA which has button DoSomething and a listener which is ActivityA.  FragmentA also defines an InterfaceA with method doSomething() in it.</p>
  
  <p>ActivityA implements InterfaceA and as below shows FragmentA (with its button DoSomething on it). </p>
  
  <p>This is the code behind implementation of DoSomething buttons click in ActivityA listener:</p>
  
  <pre><code>@Override
  public void doSomething(View v) {
    if (hasRight == false){
      // doShowPINDialogFragment just creates and shows PINDialogFragment
      // as per code below.
      // Question 1: How to make doShowPINDialogFragment() return boolean?
      if (doShowPINDialogFragment() == false){ 
          return;
      }
    }
  
    // If I put break point here, I would expect to see my dialog fragment
    // created in doShowPINDialogFragment() call above but I dont.
    // I see fragment B loaded (replacing FragmentA), then my
    // PINDialogFragment shows on top of it. 
    // Question 2: How to prevent loading fragment B before user enters
    // correct PIN?
    loadFragmentB();  
  
  }
  </code></pre>
  
  <p>Method doShowPINDialogFragment() will simply create and "show" fragment:</p>
  
  <pre><code>public void doShowPINDialogFragment(String a){
      FragmentTransaction ft = getFragmentManager().beginTransaction();
      Fragment prev = getFragmentManager().findFragmentByTag("doShowPINDialogFragment");
      if (prev != null){
          ft.remove(prev);
      }
      ft.addToBackStack(null);
      PINDialogFragment pinDialogFragment = PINDialogFragment.newInstance(a);
      pinDialogFragment.show(ft, "doShowPINDialogFragment");
  }
  </code></pre>
  
  <p>Problem is that Android will not block when showing a Dialog (like in case of ModalDialog in C#).  As a result, the method above will execute completely before showing my PINDialogFragment.  I would like to prevent call to loadFragmentB() but call it only when PINDialogFragment returns true.</p>
  
  <p>My problem is that I dont know 2 things:</p>
  
  <ol>
  <li><p>How to make above doShowPINDialogFragment() return true or false?</p></li>
  <li><p>How to prevent call to loadFragmentB() if doShowPINDialogFragment() returns false?</p></li>
  </ol>
  
  <p>I was thinking that writing it something like this would solve my 2 problems:</p>
  
  <pre><code>@Override
  public void doSomething(View v) {
    if (hasRight == false){
      if (doShowPINDialogFragment() == false){ 
          return;
      } else {
        loadFragmentB();
      }
    }
  }
  </code></pre>
  
  <p>Much appreciated.</p>