我遇到了一些障碍.我有一个非常类似于下面描述的场景:DialogFragment - 在屏幕旋转后保留监听器
建议的解决方案适用于作者,因为他的对话框是从活动中调用的.我的情况完全相同,但我的自定义对话框是从片段而不是活动调用的.(IE Activity-> Fragment-> Dialog)
我实现了相同的解决方案(在调用Fragment中设置onResume中的监听器)但在这种情况下它不起作用.
似乎正在发生的事情是,当屏幕旋转时,Android会杀死Dialog和Fragment.然后按顺序重新创建它们.因此,当我的自定义对话框上调用onCreateDialog时,包含的片段尚未重新创建,因此它为侦听器设置为正和负按钮时为null.
有没有人知道这方面的方法?
如果有人认为有必要,我可以发布代码,但它与链接线程上的代码几乎相同.
更新代码:
public class RecipeDetailEditFragment extends SherlockFragment implements DialogInterface.OnClickListener {
private EditStepFragmentDialog stepDialog;
private Recipe newRecipe; //main data object implements parcelable
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
stepDialog = EditStepFragmentDialog.newInstance(newRecipe);
//I've also tried passing 'this' into the newInstance constructor and
//setting the listener there, but that doesn't work either
}
public void onResume() {
stepDialog.setListener(this);
super.onResume();
}
...
}
public class EditStepFragmentDialog extends DialogFragment {
private DialogInterface.OnClickListener …
Run Code Online (Sandbox Code Playgroud) android android-lifecycle android-fragments android-dialogfragment
我有一个包含多个工作表的工作簿,每个工作表都有相同的命名范围集(IE它们的范围是工作表,而不是工作簿).
我想根据任何工作表上的命名范围进行查询.有些工作表的名称没有空格,而其他工作表的名称则带有空格.
我可以很容易地为没有空格的那些做这个,但用空格做这个的语法逃避了我(和一小时的谷歌).
命名范围是"成分",一张名为"NoSpaces",另一张名为"With Spaces"
这是适用于"NoSpaces"表的代码:
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dictNewRecipesToCheck(arrKeys(0)) & ";Extended Properties=""Excel 12.0;HDR=No;IMEX=1;"""
strQuery = "Select * from [NoSpaces$Ingredients]"
Set objConn = New ADODB.Connection
Set objRecordSet = New ADODB.Recordset
objConn.Open sConnString
objRecordSet.Open strQuery, objConn
Run Code Online (Sandbox Code Playgroud)
我已经为"With Spaces"表单尝试了以下所有内容:
strQuery = "Select * from [With Spaces$Ingredients]"
strQuery = "Select * from ['With Spaces'$Ingredients]"
strQuery = "Select * from ['With Spaces$'Ingredients]"
strQuery = "Select * from [With_Spaces$Ingredients]"
Run Code Online (Sandbox Code Playgroud)
每次,我得到"Microsoft Access数据库引擎找不到对象..."错误.
正如我所提到的,它适用于名称中没有空格的所有工作表.
任何帮助使这个工作在带空格的工作表上,将非常感谢.
谢谢!
基于以下评论的更新:
Excel 2007
sConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strFileLoc …
Run Code Online (Sandbox Code Playgroud)