无法在 PagerAdapter Android 中初始化 getSupportFragementManager



我正在尝试在PagerAdapter Adapter类的ViewPager中显示Google地图,当我尝试初始化Google地图Fragement时,我无法。这是我的代码:

public class GraphAdapter extends PagerAdapter {
private Context context;
private List<GraphModel> graphModels;
private Activity activity;

public GraphAdapter(Context context, List<GraphModel> graphModels, Activity activity) {
this.context = context;
this.graphModels = graphModels;
this.activity = activity;
}
@Override
public int getCount() {
return graphModels.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view.equals(object);
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, final int position) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.graph_component,container, false);
FontsEngine.overrideTypeface_SemiBold(context,view);
SupportMapFragment mapFragment = (SupportMapFragment) activity.getSupportFragmentManager().findFragmentById(R.id.map); 
}

我收到错误:

无法解析 getSupportFragementManager

任何建议都将是一个很大的帮助!提前感谢!

您可以尝试使用FragmentActivityAppCompatActivity代替构造函数参数中的活动。

相关内容

  • 没有找到相关文章

最新更新