Sigmund
Sigmund

Reputation: 788

How to call AppCompatDialogFragment from Fragment

I have a class that extends from AppCompatDialogFragment

public class SendLetterDialogFragment extends AppCompatDialogFragment {
public static SendLetterDialogFragment newInstance() {

    Bundle args = new Bundle();
    SendLetterDialogFragment fragment = new SendLetterDialogFragment();
    fragment.setArguments(args);
    return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.send_letter_dialog_fragment, container, false);
    ButterKnife.bind(this, view);
    return view;
}

}

When I show it from Activity(using `getSupportFragmentManager) it works. But I can't use this method in Fragment:

SendLetterDialogFragment fragment = SendLetterDialogFragment.newInstance();
    fragment.show(getFragmentManager(), "lol");

I've read some related issues like this Error showing support.v7.AppCompatDialogFragment using show() method but they didn't help me.

How to show AppCompatDialogFragment from the Fragment?

P.S. The activity, where the fragment places extends AppComtapActivity. Calling getChildFragmentManager instead of getFragmentManager doesn't help.

Screenshot

EDIT

I didn't solve this problem, so I decided to create dialog with AlertDialog.Builder.

Upvotes: 0

Views: 3652

Answers (1)

Divyesh Boda
Divyesh Boda

Reputation: 258

Use getChildFragmentManager() instead of getFragmentManager().

Upvotes: 2

Related Questions