Skip to content Skip to sidebar Skip to footer

Getsupportfragmentmanager() Undefined In Fragment

i'm getting error on getSupportFragmentManager() that 'this method undefine in Fragment', while creating slider menu with sliding tab i prepared code as bellow.. public class HomeF

Solution 1:

Just replace:

getSupportFragmentManager()

with:

getFragmentManager()

If you are using a android.support.v4.app.Fragment it will return a android.support.v4.app.FragmentManager (SupportFragmentManager)

If you are using a android.app.Fragment it will return a android.app.FragmentManager


Keep in mind that it handled different that in Activities.Like in the android.support.v4.app.FragmentActivity. There you have got getSupportFragmentManager() and getFragmentManager()

Solution 2:

getSupportFragmentManager() is used when your activity extends FragmentActivity or AppCompatActivity. If you are extending Activity , you need to use getFragmentManager() instead.

If you are extending FragmentActivity , make sure you are importing android.support.v4.app.FragmentActivity.

Also note that getSupportFragmentManager() is available for android.support.v4.app.Fragment not android.app.Fragment.

Also you need to return your rootView at the end of onCreateView().

Solution 3:

Are you sure you have the correct import? This one: import android.support.v4.app.Fragment; and not this: import android.app.Fragment;

Edit: Note that your code after "return rootView" on onCreateView will never be executed because you have a return before.

Post a Comment for "Getsupportfragmentmanager() Undefined In Fragment"