I can not have getSupportFragmentManager ()

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Switch;'

I try to click on an item in a list that is in a fragmnet to take me to another fragment

asked by Sergio 18.01.2017 в 00:07

1 answer


You must import Fragment and FragmentManager of android.support.v4.app.Fragment and android.support.v4.app.FragmentManager respectively (NO of android.app.Fragment and android.app.FragmentManager ).


    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;


FragmentManager fm = getSupportFragmentManager();

If you claim to have the above, then the problem is the context, the context you would use would be the Activity containing the Fragment , in this case it should be:

FragmentManager fm = getActivity().getSupportFragmentManager()
answered by 18.01.2017 / 00:13