问题
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 ?
回答1:
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
回答2:
Try this:
public void show(@NotNull android.app.FragmentManager manager, java.lang.String tag)
来源:https://stackoverflow.com/questions/35270720/error-showing-support-v7-appcompatdialogfragment-using-show-method