我正在以常规方式使用寻呼机视图。在下面的代码中我收到错误:android.support.v4.app.FragmentManager cannot be applied to android.app.FragmentManager
。我检查了所有的解决方案,并实现了它们可以看到(导入似乎没问题),但我仍然有这个错误......
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
public class MyActivity extends FragmentActivity {
private static int NUM_PAGES = 0; //The number of pages to show.
private static ViewPager mPager; //The pager widget
private static PagerAdapter mPagerAdapter; //The pager adapter
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mPager = (ViewPager) findViewById(R.id.pager);
//Next line is error
mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
mPager.setAdapter(mPagerAdapter);
}
/**
* A simple pager adapter
*/
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return MyFragment.create(position);
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
...
}
答案 0 :(得分:4)
使用getSupportFragmentManager()
代替getFragmentManager()
。根据您班级的导入,您使用的是支持库中的Fragment