JAAAY JAAAY - 3 months ago 60
Android Question

Android : android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager

I'm trying to create an adapter for my fragments but I get this :

Error:(19, 72) error: incompatible types: android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager

This is a part of my main activity:

import android.app.Activity;
import android.support.v4.view.ViewPager;
import android.os.Bundle;

public class MainActivity extends Activity {

CustomPagerAdapter mCustomPagerAdapter;
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// == Setting up the ViewPager ==

mCustomPagerAdapter = new CustomPagerAdapter(getFragmentManager(),this); <--- Error is on this line


And this is a part of my customAdapter class :

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class CustomPagerAdapter extends FragmentPagerAdapter {

protected Context mContext;

public CustomPagerAdapter(FragmentManager fm, Context context) {
super(fm);
mContext = context;
}


I appreciate any help!

Answer

Your MainActivity should extend FragmentActivity and you should use getSupportFragmentManager() method instead of getFragmentManager().

Comments