2

im really in trouble here. I am trying to open a dialog fragment from a fragment, but i cannot get it to work

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

public class FragmentDiscover extends Fragment
{
    private View rootView;
    private ImageButton folderButton;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.activity_9a_discover , container, false);
        bindActivity();
        return rootView;
    }
    private void bindActivity()
    {
        cardStack = (SwipeDeck) rootView.findViewById(R.id.main_frag_swipe_deck);
        dragCheckbox = (CheckBox) rootView.findViewById(R.id.main_frag_checkbox_drag);
        dragCheckbox.setVisibility(View.GONE);
        //Folder button
        final android.app.FragmentManager fragmentManager = getFragmentManager();

        FragmentManager fragmentManager1 = getFragmentManager();//RED LINE ERROR?!?!?

        final FoldersDialogFragment foldersDialogFragment = new FoldersDialogFragment();
        folderButton = (ImageButton) rootView.findViewById(R.id.main_button_folders);
        folderButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                foldersDialogFragment.show(fragmentManager, "folderPop");
            }
        });
        makeSomeSampleCards();
    }

So with FragmentManager fragmentManager1 = getFragmentManager();

The line foldersDialogFragment.show(fragmentManager, "folderPop"); becomes a red line error.

And with FragmentManager fragmentManager1 = getSupportFragmentManager;
using the v4 import, that gives me a redline error.

And I have no idea how to solve this...hope for your guy's wisdom!

cheers!

Matthew Shearer
  • 2,715
  • 3
  • 23
  • 32
TheQ
  • 1,949
  • 10
  • 38
  • 63
  • Are you sure that's the line with the error? If those imports are actually what you have in that class file, it should be the line above it giving an error. – Mike M. Jan 17 '17 at 23:38

1 Answers1

4

When you are within a Fragment, you use getChildFragmentManager() to retrieve a android.support.v4.app.FragmentManager for adding child fragments (fragments owned by other fragments).

Of course, you should also make sure you are using android.support.v4.DialogFragment as the base class for your FoldersDialogFragment.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443