Azim Ansari February 2016

Error showing support.v7.AppCompatDialogFragment using show() method

I am using v7 support AppCompatDialogFragment in my app

import android.support.v7.app.AppCompatDialogFragment;

public class LoginDialogFragment extends AppCompatDialogFragment {

}

Throughout the app I am using default Fragment and FragmentManager and NOT android.support.v4.app.Fragment or adroid.support.v4.app.FragmentManager

import android.app.Fragment;
import android.app.FragmentManager;

Now the problem is I want to show the dialog from an Activity by calling the method

public void show(@NotNull android.support.v4.app.FragmentManager manager,
                 java.lang.String tag)

Which does not accept android.app.FragmentManager as parameter.

So I can't call

LoginDialogFragment loginDialogFragment = new LoginDialogFragment();
loginDialogFragment.show(getFragmentManager(), "tag");

HOW TO SHOW DIALOG NOW ?

Answers


Blackbelt February 2016

You can't use the native Fragment support with AppCompatDialogFragment. In fact, if you check closer the import of AppCompatDialogFragment, you will find out that it comes from the support library. You have to use getSupportFragmentManager() instead of getFragmentManager(). Like

loginDialogFragment.show(getSupportFragmentManager(), "tag");

everything from AppCompat* is from the support library


Illya Bublyk February 2016

Try this fix public void show(@NotNull android.app.FragmentManager manager, java.lang.String tag)

Post Status

Asked in February 2016
Viewed 3,465 times
Voted 11
Answered 2 times

Search




Leave an answer