android.support.v4.app.FragmentTransaction required

前端 未结 6 1519
别跟我提以往
别跟我提以往 2021-02-05 03:54

entering in code like this:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

comes up with this error \"androi

相关标签:
6条回答
  • 2021-02-05 04:19

    getActivity() slove my issueandroid.app.FragmentManager fragmentManager = getActivity().getFragmentManager();

    0 讨论(0)
  • 2021-02-05 04:27

    In Activity import android.app.Fragment .. In Fragment extend with android.app.Fragment.. this solved my issue...

    0 讨论(0)
  • 2021-02-05 04:34

    Have you import android.support.v4.jar file to your project??

    0 讨论(0)
  • 2021-02-05 04:34

    Ok...Just make a method for fragment and call this Like:

    void addfragment(Fragment fragment, boolean addBacktoStack, int transition) {
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.replace(R.id.simple_fragment, fragment);
        ft.setTransition(transition);
        if (addBacktoStack)
            ft.addToBackStack(null);
        ft.commit();
    
    }
    

    Now Just call Your Fragment:

    addfragment(new DescriptionFragment(this),true, FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    
    0 讨论(0)
  • 2021-02-05 04:35

    try this

    public class DescriptionFragment extends android.support.v4.app.Fragment

    instead of simply Fragment.

    0 讨论(0)
  • 2021-02-05 04:44

    With getSupportFragmentManager() you are getting the supportLibrary fragmentManager instead of the systems fragmentManager. So you are working with a transaction of the supportlibrary.

    This is the reason why you need to add all these imports and use android.support.v4.app.

    If you want to get the systems fragmentManager just try to use getFragmentManager() instead getSupportFragmentManager().

    Hope this helps

    0 讨论(0)
提交回复
热议问题