0

我有一个测试变量是否为空的应用程序。如果它为空,我会显示一个设置变量的对话框。问题是在显示框时活动继续执行。我希望我的活动挂起并等待对话框的结果然后恢复。我怎样才能做到这一点?

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);

        }
4

2 回答 2

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
 ...
}
于 2012-10-22T22:43:57.420 回答
0

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

于 2012-10-22T16:27:17.657 回答