title: How can I prevent UI thread from going on until password input is right
body: <p>I am writing an Android file viewer to provided for the host app, our viewer is a fragment , and host app use newinstance to use our fragment. Some codes are as below:</p>
  
  <pre><code>newInstance () {
  ......
  openfile();
  return fragment;
  }
  
  openfile() {
  ......
  if(ispasswordfile) {
      showPasswordInputDialog;
      mpassword = .;
      mpagecount = ..;
      ......;
      return errorcode;
  } else {
      .......
  }
  }
  
   showPasswordDialog() {
       ......
       dialog.show();
       EditText edittext = dialog.findViewById(...);
       edittext.addListener(){
           override
           public boolean action....{
               .......
               if(password is right) {
                   .....
               }
           }
       };
  </code></pre>
  
  <p>My question is when dialog input password is right and then execute the sentences after showPasswordInputDialog. These codes are all running in UI thread, and listener need to change the UI if password is wrong, so I cannot pause the UI thread. So are there any ways to set a barrier between showPasswordInputDialog; and mpassword = .; And when the password is right I will remove the barrier and let the UI thread going down.
  I try to use a while loop it does not work. And I cannot add actions in the listener when password is right, because I want to return the fragment by newInstance.</p>
  
  <p>This has bothered me a long time, and help is appreciated!</p>