在我的应用程序中,我有一个片段类,其活动类为AppCompatActivity
,特别是片段我有一个ViewPager
,我想使用FragmentStatePagerAdapter
内部类充气。
适配器类:
private class SliderAdapter extends FragmentStatePagerAdapter{
List<android.support.v4.app.Fragment> frags;
Context ctx;
public SliderAdapter(FragmentManager fm, List<android.support.v4.app.Fragment> frags, Context ctx) {
super(fm);
this.frags = frags;
this.ctx = ctx;
}
@Override
public android.support.v4.app.Fragment getItem(int position) {
return frags.get(position);
}
@Override
public int getCount() {
return frags.size();
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
RelativeLayout rl = (RelativeLayout) container.inflate(ctx,R.layout.news_pager_layout,null);
ImageView img = (ImageView) rl.findViewById(R.id.slidr_img);
TextView catTxt = (TextView) rl.findViewById(R.id.catTxt);
TextView titleText = (TextView) rl.findViewById(R.id.slider_text);
TextView viewCount = (TextView) rl.findViewById(R.id.view_count);
((ViewPager)container).addView(rl);
return rl;
}
}
现在我试图从包含ViewPager的片段类中将FragmentManager
传递给它但是我收到了不兼容参数的错误
SliderAdapter adp = new SliderAdapter(getChildFragmentManager(),list);
答案 0 :(得分:0)
使用getSupportFragmentManager() SliderAdapter adp = new SliderAdapter(getSupportFragmentManager(),list);