2012-10-22 35 views
0

我有一个应用程序,测试变量是否为null。如果它是空的,我显示一个对话框,设置变量。问题在于活动在框显示时继续执行。我希望我的活动挂起并等待对话框的结果,然后继续。我该如何实现这个目标?如何暂停对话框的结果的活动

if(nfcscannerapplication.getCompId() == null || 
            nfcscannerapplication.getCompId().trim().equalsIgnoreCase("null")){ 
      Log.e(TAG, "compid null***********"); 
      showPasswordDialogBox(); 



     }else{ 

      Log.e(TAG, "compid not null***********"); 
      String[] paramsCompOpt = new String[]{nfcscannerapplication.getCompId()}; 
      AsyncGetCompanyOptions agco = new AsyncGetCompanyOptions(); 
      agco.execute(paramsCompOpt); 

     } 

回答

1

尝试类似:

preMethod() { 
     // Your actual code... 
     if(nfcscannerapplication.getCompId() == null || nfcscannerapplication.getCompId().trim().equalsIgnoreCase("null")){ 
        Log.e(TAG, "compid null***********"); 


       // Call postMethod() once the variable is set in the Dialog box** 
       showPasswordDialogBox(); 

      } else{ 

       Log.e(TAG, "compid not null***********"); 
       String[] paramsCompOpt = new String[]{nfcscannerapplication.getCompId()}; 
       AsyncGetCompanyOptions agco = new AsyncGetCompanyOptions(); 
       agco.execute(paramsCompOpt); 

       postMethod();  
      } 
} 

postMethod() { 
    // Code to execute when the variable is set 
... 
} 
0

你可以把需要的私有方法要设置的变量的代码。然后,如果变量已正确初始化,则调用该方法。或者如果没有正确初始化,则显示对话框并在关闭处理程序中调用私有方法。