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

。_饼干妹妹 提交于 2019-12-14 03:27:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!