FragmentManager无法转换为android

FragmentManager无法转换为android

我正在尝试为我的片段创建一个适配器,但是我得到了:

错误:(19,72)错误:不兼容的类型:android.app.FragmentManager无法转换为android.support.v4.app.FragmentManager

这是我主要活动的一部分:

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


这是我的customAdapter类的一部分:

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;
}


感谢您的帮助!

最佳答案

您的MainActivity应该扩展FragmentActivity,并且应该使用getSupportFragmentManager()方法而不是getFragmentManager()

07-26 01:24