Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

android - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...