Java DialogFragment不可见但可选择

Java DialogFragment不可见但可选择,java,android,fragment,dialogfragment,Java,Android,Fragment,Dialogfragment,我在Android上使用DialogFragments时遇到了一个非常奇怪的问题。 我有一个没有内容的FrameLayout,并且OnClickListener设置为打开一个FragmentDialog,用户可以在其中选择要添加的内容类型。 如果我从图库中选择一个图像,将加载此图像,并在框架布局中创建图像视图,并显示图像。如果用户再次单击布局,选择对话框将再次打开,用户可以选择新图像,旧图像将被替换 这在我使用安卓4.1的设备上运行得很好。但如果我在Android 2.3上测试它,会发生一些奇怪

我在Android上使用
DialogFragments
时遇到了一个非常奇怪的问题。 我有一个没有内容的
FrameLayout
,并且
OnClickListener
设置为打开一个
FragmentDialog
,用户可以在其中选择要添加的内容类型。 如果我从图库中选择一个图像,将加载此图像,并在框架布局中创建图像视图,并显示图像。如果用户再次单击布局,选择对话框将再次打开,用户可以选择新图像,旧图像将被替换

这在我使用安卓4.1的设备上运行得很好。但如果我在Android 2.3上测试它,会发生一些奇怪的事情: 第一个对话框出现,用户可以从库中选择图像。但是,如果用户再次单击,则不会再次显示对话框。但是显示会变暗,好像对话框会在那里,但没有显示。如果我点击选择对话框的位置,库将再次启动。因此,对话框肯定在那里,但它只是没有显示

为了解决这个问题,我已经尝试了几乎所有我想到的方法(以及我在互联网上找到的方法),但它没有任何帮助。当然,我正在使用支持库导入片段和
DialogFragment

我从嵌入
ViewPager
的片段启动此对话框。因此,它基本上是一个选项卡式视图。有趣的是:我遇到了这个错误,显示变得越来越暗,但没有对话框可见,我可以取消不可见的对话框,只需将
ViewPager
向左或向右拖动一点(到下一个片段),如果我返回并再次单击内容,对话框将再次显示。 但是,如果我拖动
ViewPager
,没有日志消息,因此我不知道如果我首先移动页面,为什么对话框会突然再次可见(只需一点点就足够了)

以下是我的一些代码:

在onCreateView方法中,我执行以下操作:

rootView = inflater.inflate(args.getInt(ARG_OBJECT_TYPE), container, false);
editorActivity = ((NoteEditorActivity) EditorSectionFragment.this.getActivity());

// ...    

if( fragmentId == R.layout.fragment_note_preferences_editor ){
            // the other page
else if( fragmentId == R.layout.fragment_note_editor ) {
            final View addLeftElement = rootView.findViewById( R.id.addLeftElement );
            final View addRightElement = rootView.findViewById( R.id.addRightElement );
            final View addTopElement = rootView.findViewById( R.id.addTopElement );
            final View addBottomElement = rootView.findViewById( R.id.addBottomElement );

            final FrameLayout contentLayout = (FrameLayout) rootView.findViewById( R.id.contentLayout );

            showNavigation(editorActivity, contentLayout, editorActivity.currentPosition.x, editorActivity.currentPosition.y);

            contentLayout.setOnClickListener( new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Log.i("CONTENT CREATOR", "create new element at " + editorActivity.currentPosition);

                    //((NoteEditorActivity) EditorSectionFragment.this.getActivity()).showContentSelectionDialog();
                    ((NoteEditorActivity) EditorSectionFragment.this.getActivity()).showCameraChooseDialog();
                }

            });
}
showCameraChoose
(我也没有使用
FragmentTransaction
,但这也不起作用)

摄影机选择对话框:

public static class CameraSelectionDialog extends DialogFragment {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {           
        final CharSequence[] items = {"Camera", "Gallery"};

        AlertDialog.Builder builder = new AlertDialog.Builder( this.getActivity() );
        builder.setTitle("Choose how to get the image!");
        builder.setItems(items, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if( which == 0){
                    ((NoteEditorActivity)(getActivity())).startCamera();
                    CameraSelectionDialog.this.dismiss();
                }
                else{ 
                    ((NoteEditorActivity)(getActivity())).startGallery();
                    CameraSelectionDialog.this.dismiss();
                }
            }
        });
        return builder.create();

    }
}
startGallery
方法只是启动一个库目的:

protected void startGallery() {
    Intent pickPhoto = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(pickPhoto , ActionCodes.GALLERY_ACTION_CODE);
}
此图像通过
onActivityResult
方法处理。但是我在onActivityResult方法中选择做什么并不重要。即使我不创建图像,问题也会出现

我不知道我能做些什么来解决这个问题,我希望你能想出这个奇怪的错误的原因。我很感激任何可能出错的建议或提示


提前谢谢你

尝试调用ft.addToBackStack(null.commit();before(new CameraSelectionDialog()).show(ft,“cameraChoose”);谢谢,但它不起作用。如果我调用commit,我将得到一个错误,因为show将再次调用commit。如果我不打电话,问题仍然存在。
protected void startGallery() {
    Intent pickPhoto = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(pickPhoto , ActionCodes.GALLERY_ACTION_CODE);
}